]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-inheritance-num2.rs
Auto merge of #22541 - Manishearth:rollup, r=Gankro
[rust.git] / src / test / run-pass / trait-inheritance-num2.rs
1
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.
5 //
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.
11
12 // A more complex example of numeric extensions
13
14 use std::cmp::{PartialEq, PartialOrd};
15 use std::num::NumCast;
16
17 pub trait TypeExt : ::std::marker::MarkerTrait { }
18
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 {}
24
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 {}
30
31 impl TypeExt for f32 {}
32 impl TypeExt for f64 {}
33
34
35 pub trait NumExt: TypeExt + PartialEq + PartialOrd + NumCast {}
36
37 impl NumExt for u8 {}
38 impl NumExt for u16 {}
39 impl NumExt for u32 {}
40 impl NumExt for u64 {}
41 impl NumExt for uint {}
42
43 impl NumExt for i8 {}
44 impl NumExt for i16 {}
45 impl NumExt for i32 {}
46 impl NumExt for i64 {}
47 impl NumExt for int {}
48
49 impl NumExt for f32 {}
50 impl NumExt for f64 {}
51
52
53 pub trait UnSignedExt: NumExt {}
54
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 {}
60
61
62 pub trait SignedExt: NumExt {}
63
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 {}
69
70 impl SignedExt for f32 {}
71 impl SignedExt for f64 {}
72
73
74 pub trait IntegerExt: NumExt {}
75
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 {}
81
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 {}
87
88
89 pub trait FloatExt: NumExt {}
90
91 impl FloatExt for f32 {}
92 impl FloatExt for f64 {}
93
94
95 fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }
96
97 pub fn main() {
98     test_float_ext(1f32);
99 }