Guest User

Untitled

a guest
Jun 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. struct Moose {
  2. name: String
  3. }
  4.  
  5. struct Deer {
  6. name: String
  7. }
  8.  
  9. trait Actions {
  10. fn baby_name(&self) -> String;
  11. }
  12.  
  13.  
  14. impl Actions for Moose {
  15. fn baby_name(&self) -> String {
  16. let new_name = format!("{}_{}", &self.name.to_string(), "kaka");
  17. new_name
  18. }
  19. }
  20.  
  21. fn give_birth<T> (data:T) -> String where T: Actions {
  22. let animal_baby = data.baby_name();
  23. animal_baby
  24. }
  25.  
  26.  
  27. fn main() {
  28. let animal = Moose {name: "tonis".to_string()};
  29. let animal2 = Deer {name: "Steve".to_string()};
  30. let animal_baby = give_birth(animal);
  31. let animal_baby2 = give_birth(animal2);
  32. println!("{}", animal_baby);
  33. }
Add Comment
Please, Sign In to add comment