trait Animal { fn create(name:&'static str) ->Self; fn name(&self)->&'static str; fn talk (&self) { println!("{} cannot talk",self.name()); } } struct Human { isim:&'static str } struct Cat { name:&'static str } impl Animal for Human { fn create(name:&'static str)->Human { Human{isim:name} } fn name(&self)->&'static str { self.isim } fn talk (&self) { println!("{} says hello",self.name()); } } impl Animal for Cat { fn create(name:&'static str)->Cat { Cat{name:name} } fn name(&self)->&'static str { self.name } fn talk (&self) { println!("{} says meow",self.name()); } } trait Summable { fn sum(&self)->T; } impl Summable for Vec { fn sum(&self) -> i32 { let mut result: i32 = 0; for x in self { result += *x; } result } } fn traits(){ //let h= Human{isim:"Enes"}; //let h=Human::create("Ahmet"); let h:Human = Animal::create("Samet"); h.talk(); let c= Cat{name:"Toprak"}; c.talk(); let a =vec![1,2,3,8,12]; println!("{:?}",a); println!("sum = {}",a.sum()); } fn main() { traits(); }