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.
11 #![feature(managed_boxes)]
14 fn speak(&mut self) -> int;
24 fn bark(&mut self) -> int {
25 println!("Woof {} {}", self.barks, self.volume);
27 if self.barks % 3u == 0u {
30 if self.barks % 10u == 0u {
33 println!("Grrr {} {}", self.barks, self.volume);
39 fn speak(&mut self) -> int {
60 fn speak(&mut self) -> int {
66 pub fn meow_count(&self) -> uint {
72 fn meow(&mut self) -> uint {
75 if self.meows % 5u == 0u {
82 fn cat(in_x: uint, in_y: int, in_name: ~str) -> cat {
91 fn annoy_neighbors(critter: &mut noisy) {
92 for _i in range(0u, 10) { critter.speak(); }
96 let mut nyan: cat = cat(0u, 2, "nyan".to_owned());
97 let mut whitefang: dog = dog();
98 annoy_neighbors(&mut nyan);
99 annoy_neighbors(&mut whitefang);
100 assert_eq!(nyan.meow_count(), 10u);
101 assert_eq!(whitefang.volume, 1);