-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// xfail-fast
use std::cmp;
-use std::int;
-use std::uint;
+#[deriving(Show)]
enum cat_type { tuxedo, tabby, tortoiseshell }
impl cmp::Eq for cat_type {
// ok: T should be in scope when resolving the trait ref for map
struct cat<T> {
// Yes, you can have negative meows
- priv meows : int,
+ meows : int,
how_hungry : int,
name : T,
pub fn eat(&mut self) -> bool {
if self.how_hungry > 0 {
- error!("OM NOM NOM");
+ println!("OM NOM NOM");
self.how_hungry -= 2;
return true;
} else {
- error!("Not hungry!");
+ println!("Not hungry!");
return false;
}
}
}
impl<T> Container for cat<T> {
- fn len(&const self) -> uint { self.meows as uint }
- fn is_empty(&const self) -> bool { self.meows == 0 }
+ fn len(&self) -> uint { self.meows as uint }
+ fn is_empty(&self) -> bool { self.meows == 0 }
}
impl<T> Mutable for cat<T> {
impl<T> cat<T> {
fn meow(&mut self) {
self.meows += 1;
- error!("Meow %d", self.meows);
+ println!("Meow {}", self.meows);
if self.meows % 5 == 0 {
self.how_hungry += 1;
}
}
pub fn main() {
- let mut nyan: cat<~str> = cat::new(0, 2, ~"nyan");
+ let mut nyan: cat<~str> = cat::new(0, 2, "nyan".to_owned());
for _ in range(1u, 5) { nyan.speak(); }
- assert!(*nyan.find(&1).unwrap() == ~"nyan");
+ assert!(*nyan.find(&1).unwrap() == "nyan".to_owned());
assert_eq!(nyan.find(&10), None);
let mut spotty: cat<cat_type> = cat::new(2, 57, tuxedo);
for _ in range(0u, 6) { spotty.speak(); }