1 pub mod kitties { 2 pub struct cat { 3 meows : usize, 4 5 pub how_hungry : isize, 6 pub name : String, 7 } 8 9 impl cat { speak(&mut self)10 pub fn speak(&mut self) { self.meow(); } 11 eat(&mut self) -> bool12 pub fn eat(&mut self) -> bool { 13 if self.how_hungry > 0 { 14 println!("OM NOM NOM"); 15 self.how_hungry -= 2; 16 return true; 17 } else { 18 println!("Not hungry!"); 19 return false; 20 } 21 } 22 } 23 24 impl cat { meow(&mut self)25 pub fn meow(&mut self) { 26 println!("Meow"); 27 self.meows += 1; 28 if self.meows % 5 == 0 { 29 self.how_hungry += 1; 30 } 31 } 32 } 33 cat(in_x : usize, in_y : isize, in_name: String) -> cat34 pub fn cat(in_x : usize, in_y : isize, in_name: String) -> cat { 35 cat { 36 meows: in_x, 37 how_hungry: in_y, 38 name: in_name 39 } 40 } 41 } 42