]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-inheritance-num2.rs
Auto merge of #22517 - brson:relnotes, 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 {}
18
19
20 impl TypeExt for u8 {}
21 impl TypeExt for u16 {}
22 impl TypeExt for u32 {}
23 impl TypeExt for u64 {}
24 impl TypeExt for uint {}
25
26 impl TypeExt for i8 {}
27 impl TypeExt for i16 {}
28 impl TypeExt for i32 {}
29 impl TypeExt for i64 {}
30 impl TypeExt for int {}
31
32 impl TypeExt for f32 {}
33 impl TypeExt for f64 {}
34
35
36 pub trait NumExt: TypeExt + PartialEq + PartialOrd + NumCast {}
37
38 impl NumExt for u8 {}
39 impl NumExt for u16 {}
40 impl NumExt for u32 {}
41 impl NumExt for u64 {}
42 impl NumExt for uint {}
43
44 impl NumExt for i8 {}
45 impl NumExt for i16 {}
46 impl NumExt for i32 {}
47 impl NumExt for i64 {}
48 impl NumExt for int {}
49
50 impl NumExt for f32 {}
51 impl NumExt for f64 {}
52
53
54 pub trait UnSignedExt: NumExt {}
55
56 impl UnSignedExt for u8 {}
57 impl UnSignedExt for u16 {}
58 impl UnSignedExt for u32 {}
59 impl UnSignedExt for u64 {}
60 impl UnSignedExt for uint {}
61
62
63 pub trait SignedExt: NumExt {}
64
65 impl SignedExt for i8 {}
66 impl SignedExt for i16 {}
67 impl SignedExt for i32 {}
68 impl SignedExt for i64 {}
69 impl SignedExt for int {}
70
71 impl SignedExt for f32 {}
72 impl SignedExt for f64 {}
73
74
75 pub trait IntegerExt: NumExt {}
76
77 impl IntegerExt for u8 {}
78 impl IntegerExt for u16 {}
79 impl IntegerExt for u32 {}
80 impl IntegerExt for u64 {}
81 impl IntegerExt for uint {}
82
83 impl IntegerExt for i8 {}
84 impl IntegerExt for i16 {}
85 impl IntegerExt for i32 {}
86 impl IntegerExt for i64 {}
87 impl IntegerExt for int {}
88
89
90 pub trait FloatExt: NumExt {}
91
92 impl FloatExt for f32 {}
93 impl FloatExt for f64 {}
94
95
96 fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }
97
98 pub fn main() {
99     test_float_ext(1f32);
100 }