use assoc types in binop traits
This commit is contained in:
parent
7095dd0070
commit
99017f82b6
36 changed files with 375 additions and 156 deletions
|
@ -8,23 +8,31 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(associated_types)]
|
||||
|
||||
use std::cmp::PartialEq;
|
||||
use std::ops::{Add, Sub, Mul};
|
||||
|
||||
trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + PartialEq + Clone { }
|
||||
trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone { }
|
||||
|
||||
#[derive(Clone, Show)]
|
||||
struct MyInt { val: int }
|
||||
|
||||
impl Add<MyInt, MyInt> for MyInt {
|
||||
impl Add for MyInt {
|
||||
type Output = MyInt;
|
||||
|
||||
fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
|
||||
}
|
||||
|
||||
impl Sub<MyInt, MyInt> for MyInt {
|
||||
impl Sub for MyInt {
|
||||
type Output = MyInt;
|
||||
|
||||
fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
|
||||
}
|
||||
|
||||
impl Mul<MyInt, MyInt> for MyInt {
|
||||
impl Mul for MyInt {
|
||||
type Output = MyInt;
|
||||
|
||||
fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue