]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/classes.rs
Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkov
[rust.git] / src / test / ui / structs-enums / classes.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(non_camel_case_types)]
4
5 struct cat {
6     meows : usize,
7
8     how_hungry : isize,
9     name : String,
10 }
11
12 impl cat {
13     pub fn speak(&mut self) { self.meow(); }
14
15     pub fn eat(&mut self) -> bool {
16         if self.how_hungry > 0 {
17             println!("OM NOM NOM");
18             self.how_hungry -= 2;
19             return true;
20         } else {
21             println!("Not hungry!");
22             return false;
23         }
24     }
25 }
26
27 impl cat {
28     fn meow(&mut self) {
29         println!("Meow");
30         self.meows += 1_usize;
31         if self.meows % 5_usize == 0_usize {
32             self.how_hungry += 1;
33         }
34     }
35 }
36
37 fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
38     cat {
39         meows: in_x,
40         how_hungry: in_y,
41         name: in_name
42     }
43 }
44
45 pub fn main() {
46   let mut nyan = cat(0_usize, 2, "nyan".to_string());
47   nyan.eat();
48   assert!((!nyan.eat()));
49   for _ in 1_usize..10_usize { nyan.speak(); };
50   assert!((nyan.eat()));
51 }