]> git.lizzy.rs Git - rust.git/blob - src/test/auxiliary/cci_class_4.rs
Rollup merge of #28991 - goyox86:goyox86/rustfmting-liblog-II, r=alexcrichton
[rust.git] / src / test / auxiliary / cci_class_4.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 pub mod kitties {
12     pub struct cat {
13         meows : usize,
14
15         pub how_hungry : isize,
16         pub name : String,
17     }
18
19     impl cat {
20         pub fn speak(&mut self) { self.meow(); }
21
22         pub fn eat(&mut self) -> bool {
23             if self.how_hungry > 0 {
24                 println!("OM NOM NOM");
25                 self.how_hungry -= 2;
26                 return true;
27             } else {
28                 println!("Not hungry!");
29                 return false;
30             }
31         }
32     }
33
34     impl cat {
35         pub fn meow(&mut self) {
36             println!("Meow");
37             self.meows += 1;
38             if self.meows % 5 == 0 {
39                 self.how_hungry += 1;
40             }
41         }
42     }
43
44     pub fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
45         cat {
46             meows: in_x,
47             how_hungry: in_y,
48             name: in_name
49         }
50     }
51 }