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.
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.
14 fn speak(&self) -> int;
18 priv barks : @mut uint,
24 fn bark(&self) -> int {
25 info!("Woof %u %d", *self.barks, *self.volume);
27 if *self.barks % 3u == 0u {
30 if *self.barks % 10u == 0u {
33 info!("Grrr %u %d", *self.barks, *self.volume);
39 fn speak(&self) -> int { self.bark() }
51 priv meows : @mut uint,
53 how_hungry : @mut int,
58 fn speak(&self) -> int { self.meow() as int }
62 pub fn meow_count(&self) -> uint { *self.meows }
66 fn meow(&self) -> uint {
69 if *self.meows % 5u == 0u {
70 *self.how_hungry += 1;
76 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
79 how_hungry: @mut in_y,
85 fn annoy_neighbors(critter: @noisy) {
86 for i in range(0u, 10) { critter.speak(); }
90 let nyan : cat = cat(0u, 2, ~"nyan");
91 let whitefang : dog = dog();
92 annoy_neighbors(@nyan.clone() as @noisy);
93 annoy_neighbors(@whitefang as @noisy);
94 assert_eq!(nyan.meow_count(), 10u);
95 assert_eq!(*whitefang.volume, 1);