rust/src/test/auxiliary/cci_class_cast.rs

49 lines
728 B
Rust
Raw Normal View History

2012-09-05 12:32:05 -07:00
use to_str::*;
use to_str::ToStr;
mod kitty {
2012-08-15 18:46:55 -07:00
struct cat : ToStr {
priv {
let mut meows : uint;
fn meow() {
2012-08-22 17:24:52 -07:00
error!("Meow");
self.meows += 1u;
if self.meows % 5u == 0u {
self.how_hungry += 1;
}
}
}
let mut how_hungry : int;
let name : ~str;
fn speak() { self.meow(); }
fn eat() -> bool {
if self.how_hungry > 0 {
2012-08-22 17:24:52 -07:00
error!("OM NOM NOM");
self.how_hungry -= 2;
2012-08-01 17:30:05 -07:00
return true;
}
else {
2012-08-22 17:24:52 -07:00
error!("Not hungry!");
2012-08-01 17:30:05 -07:00
return false;
}
}
fn to_str() -> ~str { self.name }
}
2012-09-05 15:58:43 -07:00
fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
cat {
meows: in_x,
how_hungry: in_y,
name: in_name
}
}
2012-09-05 15:58:43 -07:00
}