]> git.proxmox.com Git - rustc.git/blame_incremental - src/test/ui/run-pass/structs-enums/class-separate-impl.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / structs-enums / class-separate-impl.rs
... / ...
CommitLineData
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// run-pass
12#![allow(non_camel_case_types)]
13
14#![feature(box_syntax)]
15
16use std::fmt;
17
18struct cat {
19 meows : usize,
20
21 how_hungry : isize,
22 name : String,
23}
24
25impl cat {
26 pub fn speak(&mut self) { self.meow(); }
27
28 pub fn eat(&mut self) -> bool {
29 if self.how_hungry > 0 {
30 println!("OM NOM NOM");
31 self.how_hungry -= 2;
32 return true;
33 }
34 else {
35 println!("Not hungry!");
36 return false;
37 }
38 }
39}
40
41impl cat {
42 fn meow(&mut self) {
43 println!("Meow");
44 self.meows += 1;
45 if self.meows % 5 == 0 {
46 self.how_hungry += 1;
47 }
48 }
49}
50
51fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
52 cat {
53 meows: in_x,
54 how_hungry: in_y,
55 name: in_name
56 }
57}
58
59impl fmt::Display for cat {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 write!(f, "{}", self.name)
62 }
63}
64
65fn print_out(thing: Box<ToString>, expected: String) {
66 let actual = (*thing).to_string();
67 println!("{}", actual);
68 assert_eq!(actual.to_string(), expected);
69}
70
71pub fn main() {
72 let nyan: Box<ToString> = box cat(0, 2, "nyan".to_string()) as Box<ToString>;
73 print_out(nyan, "nyan".to_string());
74}