Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Template {
- name: &'static str,
- path: &'static str,
- }
- impl std::fmt::Display for Template {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(f, "hello {} {}", self.name, self.path)
- }
- }
- trait Tera {
- fn do_something(&self);
- }
- impl Tera for Template {
- fn do_something(&self) {
- println!("Dude where's my car");
- }
- }
- /// Arrays of the templates to use to generate the skeleton projects.
- /// These are embedded within the executable at build time.
- const MICROSERVICE_TEMPLATES: [Template; 2] = [
- Template {
- name: ".gitignore",
- path: "../../templates/microservice/.gitignore",
- },
- Template {
- name: ".dockerignore",
- path: "../../templates/microservice/.dockerignore",
- },
- ];
- const API_TEMPLATES: [Template; 1] = [
- Template {
- name: ".gitignoooooooooooooooore",
- path: "../../templates/microservice/.gitignore",
- },
- ];
- fn print_contents(templates: &[Template]) {
- templates.into_iter().for_each(|t| println!("{}", t));
- }
- fn tera_contents<T: Tera>(templates: &[T]) {
- templates.into_iter().for_each(|t| t.do_something());
- }
- fn main() {
- print_contents(&MICROSERVICE_TEMPLATES);
- print_contents(&API_TEMPLATES);
- tera_contents(&MICROSERVICE_TEMPLATES);
- tera_contents(&API_TEMPLATES);
- }
Add Comment
Please, Sign In to add comment