2 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
3 // file at the top-level directory of this distribution and at
4 // http://rust-lang.org/COPYRIGHT.
6 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 // option. This file may not be copied, modified, or distributed
10 // except according to those terms.
12 // A more complex example of numeric extensions
14 use std::cmp::{PartialEq, PartialOrd};
15 use std::num::NumCast;
17 pub trait TypeExt : ::std::marker::MarkerTrait { }
19 impl TypeExt for u8 {}
20 impl TypeExt for u16 {}
21 impl TypeExt for u32 {}
22 impl TypeExt for u64 {}
23 impl TypeExt for uint {}
25 impl TypeExt for i8 {}
26 impl TypeExt for i16 {}
27 impl TypeExt for i32 {}
28 impl TypeExt for i64 {}
29 impl TypeExt for int {}
31 impl TypeExt for f32 {}
32 impl TypeExt for f64 {}
35 pub trait NumExt: TypeExt + PartialEq + PartialOrd + NumCast {}
38 impl NumExt for u16 {}
39 impl NumExt for u32 {}
40 impl NumExt for u64 {}
41 impl NumExt for uint {}
44 impl NumExt for i16 {}
45 impl NumExt for i32 {}
46 impl NumExt for i64 {}
47 impl NumExt for int {}
49 impl NumExt for f32 {}
50 impl NumExt for f64 {}
53 pub trait UnSignedExt: NumExt {}
55 impl UnSignedExt for u8 {}
56 impl UnSignedExt for u16 {}
57 impl UnSignedExt for u32 {}
58 impl UnSignedExt for u64 {}
59 impl UnSignedExt for uint {}
62 pub trait SignedExt: NumExt {}
64 impl SignedExt for i8 {}
65 impl SignedExt for i16 {}
66 impl SignedExt for i32 {}
67 impl SignedExt for i64 {}
68 impl SignedExt for int {}
70 impl SignedExt for f32 {}
71 impl SignedExt for f64 {}
74 pub trait IntegerExt: NumExt {}
76 impl IntegerExt for u8 {}
77 impl IntegerExt for u16 {}
78 impl IntegerExt for u32 {}
79 impl IntegerExt for u64 {}
80 impl IntegerExt for uint {}
82 impl IntegerExt for i8 {}
83 impl IntegerExt for i16 {}
84 impl IntegerExt for i32 {}
85 impl IntegerExt for i64 {}
86 impl IntegerExt for int {}
89 pub trait FloatExt: NumExt {}
91 impl FloatExt for f32 {}
92 impl FloatExt for f64 {}
95 fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }