use cmp::Eq; pub trait MyNum : Add, Sub, Mul, Eq { } pub struct MyInt { val: int } pub impl MyInt : Add { pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } } pub impl MyInt : Sub { pure fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) } } pub impl MyInt : Mul { pure fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) } } pub impl MyInt : Eq { pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val } pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) } } pub impl MyInt : MyNum; pure fn mi(v: int) -> MyInt { MyInt { val: v } }