]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // A more complex example of numeric extensions | |
12 | ||
9346a6ac | 13 | pub trait TypeExt {} |
223e47cc LB |
14 | |
15 | impl TypeExt for u8 {} | |
16 | impl TypeExt for u16 {} | |
17 | impl TypeExt for u32 {} | |
18 | impl TypeExt for u64 {} | |
c34b1796 | 19 | impl TypeExt for usize {} |
223e47cc LB |
20 | |
21 | impl TypeExt for i8 {} | |
22 | impl TypeExt for i16 {} | |
23 | impl TypeExt for i32 {} | |
24 | impl TypeExt for i64 {} | |
c34b1796 | 25 | impl TypeExt for isize {} |
223e47cc LB |
26 | |
27 | impl TypeExt for f32 {} | |
28 | impl TypeExt for f64 {} | |
223e47cc LB |
29 | |
30 | ||
9346a6ac | 31 | pub trait NumExt: TypeExt + PartialEq + PartialOrd {} |
223e47cc LB |
32 | |
33 | impl NumExt for u8 {} | |
34 | impl NumExt for u16 {} | |
35 | impl NumExt for u32 {} | |
36 | impl NumExt for u64 {} | |
c34b1796 | 37 | impl NumExt for usize {} |
223e47cc LB |
38 | |
39 | impl NumExt for i8 {} | |
40 | impl NumExt for i16 {} | |
41 | impl NumExt for i32 {} | |
42 | impl NumExt for i64 {} | |
c34b1796 | 43 | impl NumExt for isize {} |
223e47cc LB |
44 | |
45 | impl NumExt for f32 {} | |
46 | impl NumExt for f64 {} | |
223e47cc LB |
47 | |
48 | ||
49 | pub trait UnSignedExt: NumExt {} | |
50 | ||
51 | impl UnSignedExt for u8 {} | |
52 | impl UnSignedExt for u16 {} | |
53 | impl UnSignedExt for u32 {} | |
54 | impl UnSignedExt for u64 {} | |
c34b1796 | 55 | impl UnSignedExt for usize {} |
223e47cc LB |
56 | |
57 | ||
58 | pub trait SignedExt: NumExt {} | |
59 | ||
60 | impl SignedExt for i8 {} | |
61 | impl SignedExt for i16 {} | |
62 | impl SignedExt for i32 {} | |
63 | impl SignedExt for i64 {} | |
c34b1796 | 64 | impl SignedExt for isize {} |
223e47cc LB |
65 | |
66 | impl SignedExt for f32 {} | |
67 | impl SignedExt for f64 {} | |
223e47cc LB |
68 | |
69 | ||
70 | pub trait IntegerExt: NumExt {} | |
71 | ||
72 | impl IntegerExt for u8 {} | |
73 | impl IntegerExt for u16 {} | |
74 | impl IntegerExt for u32 {} | |
75 | impl IntegerExt for u64 {} | |
c34b1796 | 76 | impl IntegerExt for usize {} |
223e47cc LB |
77 | |
78 | impl IntegerExt for i8 {} | |
79 | impl IntegerExt for i16 {} | |
80 | impl IntegerExt for i32 {} | |
81 | impl IntegerExt for i64 {} | |
c34b1796 | 82 | impl IntegerExt for isize {} |
223e47cc LB |
83 | |
84 | ||
1a4d82fc | 85 | pub trait FloatExt: NumExt {} |
223e47cc LB |
86 | |
87 | impl FloatExt for f32 {} | |
88 | impl FloatExt for f64 {} | |
223e47cc LB |
89 | |
90 | ||
1a4d82fc | 91 | fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) } |
223e47cc LB |
92 | |
93 | pub fn main() { | |
94 | test_float_ext(1f32); | |
95 | } |