]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/class-implement-trait-cross-crate.rs
auto merge of #13600 : brandonw/rust/master, r=brson
[rust.git] / src / test / run-pass / class-implement-trait-cross-crate.rs
1 // Copyright 2012-2014 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.
4 //
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.
10
11 // aux-build:cci_class_trait.rs
12 extern crate cci_class_trait;
13 use cci_class_trait::animals::noisy;
14
15 struct cat {
16   meows: uint,
17
18   how_hungry : int,
19   name : ~str,
20 }
21
22 impl cat {
23     pub fn eat(&mut self) -> bool {
24         if self.how_hungry > 0 {
25             println!("OM NOM NOM");
26             self.how_hungry -= 2;
27             return true;
28         }
29         else {
30             println!("Not hungry!");
31             return false;
32         }
33     }
34 }
35
36 impl noisy for cat {
37     fn speak(&mut self) { self.meow(); }
38 }
39
40 impl cat {
41     fn meow(&mut self) {
42         println!("Meow");
43         self.meows += 1u;
44         if self.meows % 5u == 0u {
45             self.how_hungry += 1;
46         }
47     }
48 }
49
50 fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
51     cat {
52         meows: in_x,
53         how_hungry: in_y,
54         name: in_name
55     }
56 }
57
58
59 pub fn main() {
60   let mut nyan = cat(0u, 2, ~"nyan");
61   nyan.eat();
62   assert!((!nyan.eat()));
63   for _ in range(1u, 10u) { nyan.speak(); };
64   assert!((nyan.eat()));
65 }