Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Moose {
- name: String
- }
- struct Deer {
- name: String
- }
- trait Actions {
- fn baby_name(&self) -> String;
- }
- impl Actions for Moose {
- fn baby_name(&self) -> String {
- let new_name = format!("{}_{}", &self.name.to_string(), "kaka");
- new_name
- }
- }
- fn give_birth<T> (data:T) -> String where T: Actions {
- let animal_baby = data.baby_name();
- animal_baby
- }
- fn main() {
- let animal = Moose {name: "tonis".to_string()};
- let animal2 = Deer {name: "Steve".to_string()};
- let animal_baby = give_birth(animal);
- let animal_baby2 = give_birth(animal2);
- println!("{}", animal_baby);
- }
Add Comment
Please, Sign In to add comment