trait Bird {
fn fly(&self);
}
struct Duck{x:i32}
struct Swan{x:i64}
impl Bird for Duck {
fn fly(&self) { println!("duck duck"); }
}
impl Bird for Swan {
fn fly(&self) { println!("swan swan");}
}
fn test<T: Bird>(arg: T) {
arg.fly();
}
fn test2(arg: Box<Bird>) {
arg.fly();
}
pub fn _main(){
test(Duck{x:10});
test(Swan{x:10});
test2( Box::new(Duck{x:10}));
test2( Box::new(Swan{x:10}));
}