Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct Cat{
- color:(u8,u8,u8),
- }
- pub struct Dog{
- color:(u8,u8,u8),
- }
- pub trait Speaker {
- fn speak(&self) -> ();
- }
- impl Speaker for Cat {
- fn speak(&self) {
- println!("meow!");
- }
- }
- impl Speaker for Dog {
- fn speak(&self) {
- println!("woof!");
- }
- }
- // fn speak<S: Speaker>() {
- // self.speak();
- //}
- pub fn notify<S: Speaker>(speaker: S) {
- speaker.speak();
- }
- fn main(){
- let cat1 = Cat{color:(30,30,30)};
- let dog1 = Dog{color:(30,30,30)};
- cat1.speak();
- dog1.speak();
- notify(cat1);
- }
Add Comment
Please, Sign In to add comment