2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2012-11-28 14:34:30 -06:00
|
|
|
// A more complex example of numeric extensions
|
|
|
|
|
2015-04-18 00:12:20 -05:00
|
|
|
pub trait TypeExt {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl TypeExt for u8 {}
|
|
|
|
impl TypeExt for u16 {}
|
|
|
|
impl TypeExt for u32 {}
|
|
|
|
impl TypeExt for u64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl TypeExt for usize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl TypeExt for i8 {}
|
|
|
|
impl TypeExt for i16 {}
|
|
|
|
impl TypeExt for i32 {}
|
|
|
|
impl TypeExt for i64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl TypeExt for isize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl TypeExt for f32 {}
|
|
|
|
impl TypeExt for f64 {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
2015-04-18 00:12:20 -05:00
|
|
|
pub trait NumExt: TypeExt + PartialEq + PartialOrd {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl NumExt for u8 {}
|
|
|
|
impl NumExt for u16 {}
|
|
|
|
impl NumExt for u32 {}
|
|
|
|
impl NumExt for u64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl NumExt for usize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl NumExt for i8 {}
|
|
|
|
impl NumExt for i16 {}
|
|
|
|
impl NumExt for i32 {}
|
|
|
|
impl NumExt for i64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl NumExt for isize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl NumExt for f32 {}
|
|
|
|
impl NumExt for f64 {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
pub trait UnSignedExt: NumExt {}
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl UnSignedExt for u8 {}
|
|
|
|
impl UnSignedExt for u16 {}
|
|
|
|
impl UnSignedExt for u32 {}
|
|
|
|
impl UnSignedExt for u64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl UnSignedExt for usize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
pub trait SignedExt: NumExt {}
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl SignedExt for i8 {}
|
|
|
|
impl SignedExt for i16 {}
|
|
|
|
impl SignedExt for i32 {}
|
|
|
|
impl SignedExt for i64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl SignedExt for isize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl SignedExt for f32 {}
|
|
|
|
impl SignedExt for f64 {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
pub trait IntegerExt: NumExt {}
|
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl IntegerExt for u8 {}
|
|
|
|
impl IntegerExt for u16 {}
|
|
|
|
impl IntegerExt for u32 {}
|
|
|
|
impl IntegerExt for u64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl IntegerExt for usize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl IntegerExt for i8 {}
|
|
|
|
impl IntegerExt for i16 {}
|
|
|
|
impl IntegerExt for i32 {}
|
|
|
|
impl IntegerExt for i64 {}
|
2015-03-25 19:06:52 -05:00
|
|
|
impl IntegerExt for isize {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
2014-01-08 05:57:31 -06:00
|
|
|
pub trait FloatExt: NumExt {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-26 19:12:00 -06:00
|
|
|
impl FloatExt for f32 {}
|
|
|
|
impl FloatExt for f64 {}
|
2012-11-28 14:34:30 -06:00
|
|
|
|
|
|
|
|
2013-09-25 00:16:43 -05:00
|
|
|
fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }
|
2012-11-28 14:34:30 -06:00
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-11-28 14:34:30 -06:00
|
|
|
test_float_ext(1f32);
|
2012-12-13 15:05:22 -06:00
|
|
|
}
|