Guest User

Untitled

a guest
Nov 22nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. struct Template {
  2. name: &'static str,
  3. path: &'static str,
  4. }
  5.  
  6. impl std::fmt::Display for Template {
  7. fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
  8. write!(f, "hello {} {}", self.name, self.path)
  9. }
  10. }
  11.  
  12. trait Tera {
  13. fn do_something(&self);
  14. }
  15.  
  16. impl Tera for Template {
  17. fn do_something(&self) {
  18. println!("Dude where's my car");
  19. }
  20. }
  21.  
  22. /// Arrays of the templates to use to generate the skeleton projects.
  23. /// These are embedded within the executable at build time.
  24. const MICROSERVICE_TEMPLATES: [Template; 2] = [
  25. Template {
  26. name: ".gitignore",
  27. path: "../../templates/microservice/.gitignore",
  28. },
  29. Template {
  30. name: ".dockerignore",
  31. path: "../../templates/microservice/.dockerignore",
  32. },
  33. ];
  34.  
  35. const API_TEMPLATES: [Template; 1] = [
  36. Template {
  37. name: ".gitignoooooooooooooooore",
  38. path: "../../templates/microservice/.gitignore",
  39. },
  40. ];
  41.  
  42. fn print_contents(templates: &[Template]) {
  43. templates.into_iter().for_each(|t| println!("{}", t));
  44. }
  45.  
  46. fn tera_contents<T: Tera>(templates: &[T]) {
  47. templates.into_iter().for_each(|t| t.do_something());
  48. }
  49.  
  50. fn main() {
  51. print_contents(&MICROSERVICE_TEMPLATES);
  52. print_contents(&API_TEMPLATES);
  53.  
  54. tera_contents(&MICROSERVICE_TEMPLATES);
  55. tera_contents(&API_TEMPLATES);
  56. }
Add Comment
Please, Sign In to add comment