]> git.proxmox.com Git - rustc.git/blob - tests/ui/structs-enums/auxiliary/cci_class_cast.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / structs-enums / auxiliary / cci_class_cast.rs
1 pub mod kitty {
2 use std::fmt;
3
4 pub struct cat {
5 meows : usize,
6 pub how_hungry : isize,
7 pub name : String,
8 }
9
10 impl fmt::Display for cat {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 write!(f, "{}", self.name)
13 }
14 }
15
16 impl cat {
17 fn meow(&mut self) {
18 println!("Meow");
19 self.meows += 1;
20 if self.meows % 5 == 0 {
21 self.how_hungry += 1;
22 }
23 }
24
25 }
26
27 impl cat {
28 pub fn speak(&mut self) { self.meow(); }
29
30 pub fn eat(&mut self) -> bool {
31 if self.how_hungry > 0 {
32 println!("OM NOM NOM");
33 self.how_hungry -= 2;
34 return true;
35 }
36 else {
37 println!("Not hungry!");
38 return false;
39 }
40 }
41 }
42
43 pub fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
44 cat {
45 meows: in_x,
46 how_hungry: in_y,
47 name: in_name
48 }
49 }
50 }