/** * These RHS operator traits would formalise the overloading of the RHS of the * Num operators (as described in [Refining Traits and Impls] * (http://smallcultfollowing.com/babysteps/blog/2012/10/04/refining-traits-slash-impls/) * by nmatsakis). For example, if you wanted to achieve something like: * * ~~~ * enum Radians = T; * * let half_rotation = Radians(float::consts::pi); * let full_rotation = 2.0 * half_rotation; * let quarter_rotation = half_rotation * 0.5; * ~~~ * * All you'd have to implement is: * * ~~~ * pub impl Radians: float::MulRHS> { * pure fn int_add_rhs(lhs: &int) -> Radians { Radians(lhs * (*self)) } * } * * pub impl Radians: Mul> { * pure fn mul(rhs: &T) -> Radians { Radians((*self) * (*rhs)) } * } * ~~~ * * I may have got something wrong in my implementations, as I got some 'multiple * applicable methods in scope' errors due to Num automatically being imported * with core. If that's the case, apologies in advance! */ use core::Num; pub mod f32 { pub trait AddRHS { pure fn f32_add_rhs(lhs: &f32) -> Result; } pub trait SubRHS { pure fn f32_sub_rhs(lhs: &f32) -> Result; } pub trait MulRHS { pure fn f32_mul_rhs(lhs: &f32) -> Result; } pub trait DivRHS { pure fn f32_div_rhs(lhs: &f32) -> Result; } pub trait ModuloRHS { pure fn f32_modulo_rhs(lhs: &f32) -> Result; } pub trait BitAndRHS { pure fn f32_bitand_rhs(lhs: &f32) -> Result; } pub trait BitOrRHS { pure fn f32_bitor_rhs(lhs: &f32 ) -> Result; } pub trait BitXorRHS { pure fn f32_bitxor_rhs(lhs: &f32) -> Result; } pub trait ShlRHS { pure fn f32_shl_rhs(lhs: &f32) -> Result; } pub trait ShrRHS { pure fn f32_shr_rhs(lhs: &f32) -> Result; } pub impl f32: AddRHS { pure fn f32_add_rhs(lhs: &f32) -> f32 { *lhs + self } } pub impl f32: SubRHS { pure fn f32_sub_rhs(lhs: &f32) -> f32 { *lhs - self } } pub impl f32: MulRHS { pure fn f32_mul_rhs(lhs: &f32) -> f32 { *lhs * self } } pub impl f32: DivRHS { pure fn f32_div_rhs(lhs: &f32) -> f32 { *lhs / self } } pub impl f32: ModuloRHS { pure fn f32_modulo_rhs(lhs: &f32) -> f32 { *lhs % self } } // pub impl f32: Num { // pure fn add(other: &f32) -> f32 { other.f32_add_rhs(&self) } // pure fn sub(other: &f32) -> f32 { other.f32_sub_rhs(&self) } // pure fn mul(other: &f32) -> f32 { other.f32_mul_rhs(&self) } // pure fn div(other: &f32) -> f32 { other.f32_div_rhs(&self) } // pure fn modulo(other: &f32) -> f32 { other.f32_modulo_rhs(&self) } // pure fn neg() -> f32 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> f32 { n as f32 } // } } pub mod f64 { pub trait AddRHS { pure fn f64_add_rhs(lhs: &f64) -> Result; } pub trait SubRHS { pure fn f64_sub_rhs(lhs: &f64) -> Result; } pub trait MulRHS { pure fn f64_mul_rhs(lhs: &f64) -> Result; } pub trait DivRHS { pure fn f64_div_rhs(lhs: &f64) -> Result; } pub trait ModuloRHS { pure fn f64_modulo_rhs(lhs: &f64) -> Result; } pub trait BitAndRHS { pure fn f64_bitand_rhs(lhs: &f64) -> Result; } pub trait BitOrRHS { pure fn f64_bitor_rhs(lhs: &f64) -> Result; } pub trait BitXorRHS { pure fn f64_bitxor_rhs(lhs: &f64) -> Result; } pub trait ShlRHS { pure fn f64_shl_rhs(lhs: &f64) -> Result; } pub trait ShrRHS { pure fn f64_shr_rhs(lhs: &f64) -> Result; } pub impl f64: AddRHS { pure fn f64_add_rhs(lhs: &f64) -> f64 { *lhs + self } } pub impl f64: SubRHS { pure fn f64_sub_rhs(lhs: &f64) -> f64 { *lhs - self } } pub impl f64: MulRHS { pure fn f64_mul_rhs(lhs: &f64) -> f64 { *lhs * self } } pub impl f64: DivRHS { pure fn f64_div_rhs(lhs: &f64) -> f64 { *lhs / self } } pub impl f64: ModuloRHS { pure fn f64_modulo_rhs(lhs: &f64) -> f64 { *lhs % self } } // pub impl f64: Num { // pure fn add(other: &f64) -> f64 { other.f64_add_rhs(&self) } // pure fn sub(other: &f64) -> f64 { other.f64_sub_rhs(&self) } // pure fn mul(other: &f64) -> f64 { other.f64_mul_rhs(&self) } // pure fn div(other: &f64) -> f64 { other.f64_div_rhs(&self) } // pure fn modulo(other: &f64) -> f64 { other.f64_modulo_rhs(&self) } // pure fn neg() -> f64 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> f64 { n as f64 } // } } pub mod float { pub trait AddRHS { pure fn float_add_rhs(lhs: &float) -> Result; } pub trait SubRHS { pure fn float_sub_rhs(lhs: &float) -> Result; } pub trait MulRHS { pure fn float_mul_rhs(lhs: &float) -> Result; } pub trait DivRHS { pure fn float_div_rhs(lhs: &float) -> Result; } pub trait ModuloRHS { pure fn float_modulo_rhs(lhs: &float) -> Result; } pub trait BitAndRHS { pure fn float_bitand_rhs(lhs: &float) -> Result; } pub trait BitOrRHS { pure fn float_bitor_rhs(lhs: &float) -> Result; } pub trait BitXorRHS { pure fn float_bitxor_rhs(lhs: &float) -> Result; } pub trait ShlRHS { pure fn float_shl_rhs(lhs: &float) -> Result; } pub trait ShrRHS { pure fn float_shr_rhs(lhs: &float) -> Result; } pub impl float: AddRHS { pure fn float_add_rhs(lhs: &float) -> float { *lhs + self } } pub impl float: SubRHS { pure fn float_sub_rhs(lhs: &float) -> float { *lhs - self } } pub impl float: MulRHS { pure fn float_mul_rhs(lhs: &float) -> float { *lhs * self } } pub impl float: DivRHS { pure fn float_div_rhs(lhs: &float) -> float { *lhs / self } } pub impl float: ModuloRHS { pure fn float_modulo_rhs(lhs: &float) -> float { *lhs % self } } // pub impl float: Num { // pure fn add(other: &float) -> float { other.float_add_rhs(&self) } // pure fn sub(other: &float) -> float { other.float_sub_rhs(&self) } // pure fn mul(other: &float) -> float { other.float_mul_rhs(&self) } // pure fn div(other: &float) -> float { other.float_div_rhs(&self) } // pure fn modulo(other: &float) -> float { other.float_modulo_rhs(&self) } // pure fn neg() -> float { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> float { n as float } // } } pub mod i8 { pub trait AddRHS { pure fn i8_add_rhs(lhs: &i8) -> Result; } pub trait SubRHS { pure fn i8_sub_rhs(lhs: &i8) -> Result; } pub trait MulRHS { pure fn i8_mul_rhs(lhs: &i8) -> Result; } pub trait DivRHS { pure fn i8_div_rhs(lhs: &i8) -> Result; } pub trait ModuloRHS { pure fn i8_modulo_rhs(lhs: &i8) -> Result; } pub trait BitAndRHS { pure fn i8_bitand_rhs(lhs: &i8) -> Result; } pub trait BitOrRHS { pure fn i8_bitor_rhs(lhs: &i8) -> Result; } pub trait BitXorRHS { pure fn i8_bitxor_rhs(lhs: &i8) -> Result; } pub trait ShlRHS { pure fn i8_shl_rhs(lhs: &i8) -> Result; } pub trait ShrRHS { pure fn i8_shr_rhs(lhs: &i8) -> Result; } pub impl i8 : AddRHS { pure fn i8_add_rhs(lhs: &i8) -> i8 { *lhs + self } } pub impl i8 : SubRHS { pure fn i8_sub_rhs(lhs: &i8) -> i8 { *lhs - self } } pub impl i8 : MulRHS { pure fn i8_mul_rhs(lhs: &i8) -> i8 { *lhs * self } } pub impl i8 : DivRHS { pure fn i8_div_rhs(lhs: &i8) -> i8 { *lhs / self } } pub impl i8 : ModuloRHS { pure fn i8_modulo_rhs(lhs: &i8) -> i8 { *lhs % self } } // pub impl i8: Num { // pure fn add(other: &i8) -> i8 { other.i8_add_rhs(&self) } // pure fn sub(other: &i8) -> i8 { other.i8_sub_rhs(&self) } // pure fn mul(other: &i8) -> i8 { other.i8_mul_rhs(&self) } // pure fn div(other: &i8) -> i8 { other.i8_div_rhs(&self) } // pure fn modulo(other: &i8) -> i8 { other.i8_modulo_rhs(&self) } // pure fn neg() -> i8 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> i8 { n as i8 } // } } pub mod i16 { pub trait AddRHS { pure fn i16_add_rhs(lhs: &i16) -> Result; } pub trait SubRHS { pure fn i16_sub_rhs(lhs: &i16) -> Result; } pub trait MulRHS { pure fn i16_mul_rhs(lhs: &i16) -> Result; } pub trait DivRHS { pure fn i16_div_rhs(lhs: &i16) -> Result; } pub trait ModuloRHS { pure fn i16_modulo_rhs(lhs: &i16) -> Result; } pub trait BitAndRHS { pure fn i16_bitand_rhs(lhs: &i16) -> Result; } pub trait BitOrRHS { pure fn i16_bitor_rhs(lhs: &i16) -> Result; } pub trait BitXorRHS { pure fn i16_bitxor_rhs(lhs: &i16) -> Result; } pub trait ShlRHS { pure fn i16_shl_rhs(lhs: &i16) -> Result; } pub trait ShrRHS { pure fn i16_shr_rhs(lhs: &i16) -> Result; } pub impl i16: AddRHS { pure fn i16_add_rhs(lhs: &i16) -> i16 { *lhs + self } } pub impl i16: SubRHS { pure fn i16_sub_rhs(lhs: &i16) -> i16 { *lhs - self } } pub impl i16: MulRHS { pure fn i16_mul_rhs(lhs: &i16) -> i16 { *lhs * self } } pub impl i16: DivRHS { pure fn i16_div_rhs(lhs: &i16) -> i16 { *lhs / self } } pub impl i16: ModuloRHS { pure fn i16_modulo_rhs(lhs: &i16) -> i16 { *lhs % self } } // pub impl i16: Num { // pure fn add(other: &i16) -> i16 { other.i16_add_rhs(&self) } // pure fn sub(other: &i16) -> i16 { other.i16_sub_rhs(&self) } // pure fn mul(other: &i16) -> i16 { other.i16_mul_rhs(&self) } // pure fn div(other: &i16) -> i16 { other.i16_div_rhs(&self) } // pure fn modulo(other: &i16) -> i16 { other.i16_modulo_rhs(&self) } // pure fn neg() -> i16 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> i16 { n as i16 } // } } pub mod i32 { pub trait AddRHS { pure fn i32_add_rhs(lhs: &i32) -> Result; } pub trait SubRHS { pure fn i32_sub_rhs(lhs: &i32) -> Result; } pub trait MulRHS { pure fn i32_mul_rhs(lhs: &i32) -> Result; } pub trait DivRHS { pure fn i32_div_rhs(lhs: &i32) -> Result; } pub trait ModuloRHS { pure fn i32_modulo_rhs(lhs: &i32) -> Result; } pub trait BitAndRHS { pure fn i32_bitand_rhs(lhs: &i32) -> Result; } pub trait BitOrRHS { pure fn i32_bitor_rhs(lhs: &i32) -> Result; } pub trait BitXorRHS { pure fn i32_bitxor_rhs(lhs: &i32) -> Result; } pub trait ShlRHS { pure fn i32_shl_rhs(lhs: &i32) -> Result; } pub trait ShrRHS { pure fn i32_shr_rhs(lhs: &i32) -> Result; } pub impl i32: AddRHS { pure fn i32_add_rhs(lhs: &i32) -> i32 { *lhs + self } } pub impl i32: SubRHS { pure fn i32_sub_rhs(lhs: &i32) -> i32 { *lhs - self } } pub impl i32: MulRHS { pure fn i32_mul_rhs(lhs: &i32) -> i32 { *lhs * self } } pub impl i32: DivRHS { pure fn i32_div_rhs(lhs: &i32) -> i32 { *lhs / self } } pub impl i32: ModuloRHS { pure fn i32_modulo_rhs(lhs: &i32) -> i32 { *lhs % self } } // pub impl i32: Num { // pure fn add(other: &i32) -> i32 { other.i32_add_rhs(&self) } // pure fn sub(other: &i32) -> i32 { other.i32_sub_rhs(&self) } // pure fn mul(other: &i32) -> i32 { other.i32_mul_rhs(&self) } // pure fn div(other: &i32) -> i32 { other.i32_div_rhs(&self) } // pure fn modulo(other: &i32) -> i32 { other.i32_modulo_rhs(&self) } // pure fn neg() -> i32 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> i32 { n as i32 } // } } pub mod i64 { pub trait AddRHS { pure fn i64_add_rhs(lhs: &i64) -> Result; } pub trait SubRHS { pure fn i64_sub_rhs(lhs: &i64) -> Result; } pub trait MulRHS { pure fn i64_mul_rhs(lhs: &i64) -> Result; } pub trait DivRHS { pure fn i64_div_rhs(lhs: &i64) -> Result; } pub trait ModuloRHS { pure fn i64_modulo_rhs(lhs: &i64) -> Result; } pub trait BitAndRHS { pure fn i64_bitand_rhs(lhs: &i64) -> Result; } pub trait BitOrRHS { pure fn i64_bitor_rhs(lhs: &i64) -> Result; } pub trait BitXorRHS { pure fn i64_bitxor_rhs(lhs: &i64) -> Result; } pub trait ShlRHS { pure fn i64_shl_rhs(lhs: &i64) -> Result; } pub trait ShrRHS { pure fn i64_shr_rhs(lhs: &i64) -> Result; } pub impl i64: AddRHS { pure fn i64_add_rhs(lhs: &i64) -> i64 { *lhs + self } } pub impl i64: SubRHS { pure fn i64_sub_rhs(lhs: &i64) -> i64 { *lhs - self } } pub impl i64: MulRHS { pure fn i64_mul_rhs(lhs: &i64) -> i64 { *lhs * self } } pub impl i64: DivRHS { pure fn i64_div_rhs(lhs: &i64) -> i64 { *lhs / self } } pub impl i64: ModuloRHS { pure fn i64_modulo_rhs(lhs: &i64) -> i64 { *lhs % self } } // pub impl i64: Num { // pure fn add(other: &i64) -> i64 { other.i64_add_rhs(&self) } // pure fn sub(other: &i64) -> i64 { other.i64_sub_rhs(&self) } // pure fn mul(other: &i64) -> i64 { other.i64_mul_rhs(&self) } // pure fn div(other: &i64) -> i64 { other.i64_div_rhs(&self) } // pure fn modulo(other: &i64) -> i64 { other.i64_modulo_rhs(&self) } // pure fn neg() -> i64 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> i64 { n as i64 } // } } pub mod int { pub trait AddRHS { pure fn int_add_rhs(lhs: &int) -> Result; } pub trait SubRHS { pure fn int_sub_rhs(lhs: &int) -> Result; } pub trait MulRHS { pure fn int_mul_rhs(lhs: &int) -> Result; } pub trait DivRHS { pure fn int_div_rhs(lhs: &int) -> Result; } pub trait ModuloRHS { pure fn int_modulo_rhs(lhs: &int) -> Result; } pub trait BitAndRHS { pure fn int_bitand_rhs(lhs: &int) -> Result; } pub trait BitOrRHS { pure fn int_bitor_rhs(lhs: &int) -> Result; } pub trait BitXorRHS { pure fn int_bitxor_rhs(lhs: &int) -> Result; } pub trait ShlRHS { pure fn int_shl_rhs(lhs: &int) -> Result; } pub trait ShrRHS { pure fn int_shr_rhs(lhs: &int) -> Result; } pub impl int: AddRHS { pure fn int_add_rhs(lhs: &int) -> int { *lhs + self } } pub impl int: SubRHS { pure fn int_sub_rhs(lhs: &int) -> int { *lhs - self } } pub impl int: MulRHS { pure fn int_mul_rhs(lhs: &int) -> int { *lhs * self } } pub impl int: DivRHS { pure fn int_div_rhs(lhs: &int) -> int { *lhs / self } } pub impl int: ModuloRHS { pure fn int_modulo_rhs(lhs: &int) -> int { *lhs % self } } // pub impl int: Num { // pure fn add(other: &int) -> int { other.int_add_rhs(&self) } // pure fn sub(other: &int) -> int { other.int_sub_rhs(&self) } // pure fn mul(other: &int) -> int { other.int_mul_rhs(&self) } // pure fn div(other: &int) -> int { other.int_div_rhs(&self) } // pure fn modulo(other: &int) -> int { other.int_modulo_rhs(&self) } // pure fn neg() -> int { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> int { n } // } } pub mod u8 { pub trait AddRHS { pure fn u8_add_rhs(lhs: &u8) -> Result; } pub trait SubRHS { pure fn u8_sub_rhs(lhs: &u8) -> Result; } pub trait MulRHS { pure fn u8_mul_rhs(lhs: &u8) -> Result; } pub trait DivRHS { pure fn u8_div_rhs(lhs: &u8) -> Result; } pub trait ModuloRHS { pure fn u8_modulo_rhs(lhs: &u8) -> Result; } pub trait BitAndRHS { pure fn u8_bitand_rhs(lhs: &u8) -> Result; } pub trait BitOrRHS { pure fn u8_bitor_rhs(lhs: &u8) -> Result; } pub trait BitXorRHS { pure fn u8_bitxor_rhs(lhs: &u8) -> Result; } pub trait ShlRHS { pure fn u8_shl_rhs(lhs: &u8) -> Result; } pub trait ShrRHS { pure fn u8_shr_rhs(lhs: &u8) -> Result; } pub impl u8: AddRHS { pure fn u8_add_rhs(lhs: &u8) -> u8 { *lhs + self } } pub impl u8: SubRHS { pure fn u8_sub_rhs(lhs: &u8) -> u8 { *lhs - self } } pub impl u8: MulRHS { pure fn u8_mul_rhs(lhs: &u8) -> u8 { *lhs * self } } pub impl u8: DivRHS { pure fn u8_div_rhs(lhs: &u8) -> u8 { *lhs / self } } pub impl u8: ModuloRHS { pure fn u8_modulo_rhs(lhs: &u8) -> u8 { *lhs % self } } // pub impl u8: Num { // pure fn add(other: &u8) -> u8 { other.u8_add_rhs(&self) } // pure fn sub(other: &u8) -> u8 { other.u8_sub_rhs(&self) } // pure fn mul(other: &u8) -> u8 { other.u8_mul_rhs(&self) } // pure fn div(other: &u8) -> u8 { other.u8_div_rhs(&self) } // pure fn modulo(other: &u8) -> u8 { other.u8_modulo_rhs(&self) } // pure fn neg() -> u8 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> u8 { n as u8 } // } } pub mod u16 { pub trait AddRHS { pure fn u16_add_rhs(lhs: &u16) -> Result; } pub trait SubRHS { pure fn u16_sub_rhs(lhs: &u16) -> Result; } pub trait MulRHS { pure fn u16_mul_rhs(lhs: &u16) -> Result; } pub trait DivRHS { pure fn u16_div_rhs(lhs: &u16) -> Result; } pub trait ModuloRHS { pure fn u16_modulo_rhs(lhs: &u16) -> Result; } pub trait BitAndRHS { pure fn u16_bitand_rhs(lhs: &u16) -> Result; } pub trait BitOrRHS { pure fn u16_bitor_rhs(lhs: &u16) -> Result; } pub trait BitXorRHS { pure fn u16_bitxor_rhs(lhs: &u16) -> Result; } pub trait ShlRHS { pure fn u16_shl_rhs(lhs: &u16) -> Result; } pub trait ShrRHS { pure fn u16_shr_rhs(lhs: &u16) -> Result; } pub impl u16: AddRHS { pure fn u16_add_rhs(lhs: &u16) -> u16 { *lhs + self } } pub impl u16: SubRHS { pure fn u16_sub_rhs(lhs: &u16) -> u16 { *lhs - self } } pub impl u16: MulRHS { pure fn u16_mul_rhs(lhs: &u16) -> u16 { *lhs * self } } pub impl u16: DivRHS { pure fn u16_div_rhs(lhs: &u16) -> u16 { *lhs / self } } pub impl u16: ModuloRHS { pure fn u16_modulo_rhs(lhs: &u16) -> u16 { *lhs % self } } // pub impl u16: Num { // pure fn add(other: &u16) -> u16 { other.u16_add_rhs(&self) } // pure fn sub(other: &u16) -> u16 { other.u16_sub_rhs(&self) } // pure fn mul(other: &u16) -> u16 { other.u16_mul_rhs(&self) } // pure fn div(other: &u16) -> u16 { other.u16_div_rhs(&self) } // pure fn modulo(other: &u16) -> u16 { other.u16_modulo_rhs(&self) } // pure fn neg() -> u16 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> u16 { n as u16 } // } } pub mod u32 { pub trait AddRHS { pure fn u32_add_rhs(lhs: &u32) -> Result; } pub trait SubRHS { pure fn u32_sub_rhs(lhs: &u32) -> Result; } pub trait MulRHS { pure fn u32_mul_rhs(lhs: &u32) -> Result; } pub trait DivRHS { pure fn u32_div_rhs(lhs: &u32) -> Result; } pub trait ModuloRHS { pure fn u32_modulo_rhs(lhs: &u32) -> Result; } pub trait BitAndRHS { pure fn u32_bitand_rhs(lhs: &u32) -> Result; } pub trait BitOrRHS { pure fn u32_bitor_rhs(lhs: &u32) -> Result; } pub trait BitXorRHS { pure fn u32_bitxor_rhs(lhs: &u32) -> Result; } pub trait ShlRHS { pure fn u32_shl_rhs(lhs: &u32) -> Result; } pub trait ShrRHS { pure fn u32_shr_rhs(lhs: &u32) -> Result; } pub impl u32: AddRHS { pure fn u32_add_rhs(lhs: &u32) -> u32 { *lhs + self } } pub impl u32: SubRHS { pure fn u32_sub_rhs(lhs: &u32) -> u32 { *lhs - self } } pub impl u32: MulRHS { pure fn u32_mul_rhs(lhs: &u32) -> u32 { *lhs * self } } pub impl u32: DivRHS { pure fn u32_div_rhs(lhs: &u32) -> u32 { *lhs / self } } pub impl u32: ModuloRHS { pure fn u32_modulo_rhs(lhs: &u32) -> u32 { *lhs % self } } // pub impl u32: Num { // pure fn add(other: &u32) -> u32 { other.u32_add_rhs(&self) } // pure fn sub(other: &u32) -> u32 { other.u32_sub_rhs(&self) } // pure fn mul(other: &u32) -> u32 { other.u32_mul_rhs(&self) } // pure fn div(other: &u32) -> u32 { other.u32_div_rhs(&self) } // pure fn modulo(other: &u32) -> u32 { other.u32_modulo_rhs(&self) } // pure fn neg() -> u32 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> u32 { n as u32 } // } } pub mod u64 { pub trait AddRHS { pure fn u64_add_rhs(lhs: &u64) -> Result; } pub trait SubRHS { pure fn u64_sub_rhs(lhs: &u64) -> Result; } pub trait MulRHS { pure fn u64_mul_rhs(lhs: &u64) -> Result; } pub trait DivRHS { pure fn u64_div_rhs(lhs: &u64) -> Result; } pub trait ModuloRHS { pure fn u64_modulo_rhs(lhs: &u64) -> Result; } pub trait BitAndRHS { pure fn u64_bitand_rhs(lhs: &u64) -> Result; } pub trait BitOrRHS { pure fn u64_bitor_rhs(lhs: &u64) -> Result; } pub trait BitXorRHS { pure fn u64_bitxor_rhs(lhs: &u64) -> Result; } pub trait ShlRHS { pure fn u64_shl_rhs(lhs: &u64) -> Result; } pub trait ShrRHS { pure fn u64_shr_rhs(lhs: &u64) -> Result; } pub impl u64: AddRHS { pure fn u64_add_rhs(lhs: &u64) -> u64 { *lhs + self } } pub impl u64: SubRHS { pure fn u64_sub_rhs(lhs: &u64) -> u64 { *lhs - self } } pub impl u64: MulRHS { pure fn u64_mul_rhs(lhs: &u64) -> u64 { *lhs * self } } pub impl u64: DivRHS { pure fn u64_div_rhs(lhs: &u64) -> u64 { *lhs / self } } pub impl u64: ModuloRHS { pure fn u64_modulo_rhs(lhs: &u64) -> u64 { *lhs % self } } // pub impl u64: Num { // pure fn add(other: &u64) -> u64 { other.u64_add_rhs(&self) } // pure fn sub(other: &u64) -> u64 { other.u64_sub_rhs(&self) } // pure fn mul(other: &u64) -> u64 { other.u64_mul_rhs(&self) } // pure fn div(other: &u64) -> u64 { other.u64_div_rhs(&self) } // pure fn modulo(other: &u64) -> u64 { other.u64_modulo_rhs(&self) } // pure fn neg() -> u64 { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> u64 { n as u64 } // } } pub mod uint { pub trait AddRHS { pure fn uint_add_rhs(lhs: &uint) -> Result; } pub trait SubRHS { pure fn uint_sub_rhs(lhs: &uint) -> Result; } pub trait MulRHS { pure fn uint_mul_rhs(lhs: &uint) -> Result; } pub trait DivRHS { pure fn uint_div_rhs(lhs: &uint) -> Result; } pub trait ModuloRHS { pure fn uint_modulo_rhs(lhs: &uint) -> Result; } pub trait BitAndRHS { pure fn uint_bitand_rhs(lhs: &uint) -> Result; } pub trait BitOrRHS { pure fn uint_bitor_rhs(lhs: &uint) -> Result; } pub trait BitXorRHS { pure fn uint_bitxor_rhs(lhs: &uint) -> Result; } pub trait ShlRHS { pure fn uint_shl_rhs(lhs: &uint) -> Result; } pub trait ShrRHS { pure fn uint_shr_rhs(lhs: &uint) -> Result; } pub impl uint: AddRHS { pure fn uint_add_rhs(lhs: &uint) -> uint { *lhs + self } } pub impl uint: SubRHS { pure fn uint_sub_rhs(lhs: &uint) -> uint { *lhs - self } } pub impl uint: MulRHS { pure fn uint_mul_rhs(lhs: &uint) -> uint { *lhs * self } } pub impl uint: DivRHS { pure fn uint_div_rhs(lhs: &uint) -> uint { *lhs / self } } pub impl uint: ModuloRHS { pure fn uint_modulo_rhs(lhs: &uint) -> uint { *lhs % self } } // pub impl uint: Num { // pure fn add(other: &uint) -> uint { other.uint_add_rhs(&self) } // pure fn sub(other: &uint) -> uint { other.uint_sub_rhs(&self) } // pure fn mul(other: &uint) -> uint { other.uint_mul_rhs(&self) } // pure fn div(other: &uint) -> uint { other.uint_div_rhs(&self) } // pure fn modulo(other: &uint) -> uint { other.uint_modulo_rhs(&self) } // pure fn neg() -> uint { -self } // pure fn to_int() -> int { self as int } // static pure fn from_int(n: int) -> uint { n as uint } // } }