2012-10-19 23:27:01 -05:00
|
|
|
trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
|
|
|
|
}
|
|
|
|
|
|
|
|
impl int : MyNum {
|
|
|
|
pure fn add(other: &int) -> int { self + *other }
|
2012-11-21 14:25:35 -06:00
|
|
|
pure fn sub(&self, other: &int) -> int { *self - *other }
|
|
|
|
pure fn mul(&self, other: &int) -> int { *self * *other }
|
2012-10-19 23:27:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn f<T:Copy MyNum>(x: T, y: T) -> (T, T, T) {
|
|
|
|
return (x + y, x - y, x * y);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let (x, y) = (3, 5);
|
|
|
|
let (a, b, c) = f(x, y);
|
|
|
|
assert a == 8;
|
|
|
|
assert b == -2;
|
|
|
|
assert c == 15;
|
|
|
|
}
|
|
|
|
|