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.
12 fn speak(&self) -> int;
16 priv barks : @mut uint,
22 fn bark(&self) -> int {
23 info!("Woof %u %d", *self.barks, *self.volume);
25 if *self.barks % 3u == 0u {
28 if *self.barks % 10u == 0u {
31 info!("Grrr %u %d", *self.barks, *self.volume);
37 fn speak(&self) -> int { self.bark() }
49 priv meows : @mut uint,
51 how_hungry : @mut int,
56 fn speak(&self) -> int { self.meow() as int }
60 pub fn meow_count(&self) -> uint { *self.meows }
64 fn meow(&self) -> uint {
67 if *self.meows % 5u == 0u {
68 *self.how_hungry += 1;
74 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
77 how_hungry: @mut in_y,
83 fn annoy_neighbors(critter: @noisy) {
84 for _i in range(0u, 10) { critter.speak(); }
88 let nyan : cat = cat(0u, 2, ~"nyan");
89 let whitefang : dog = dog();
90 annoy_neighbors(@nyan.clone() as @noisy);
91 annoy_neighbors(@whitefang as @noisy);
92 assert_eq!(nyan.meow_count(), 10u);
93 assert_eq!(*whitefang.volume, 1);