File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -65,13 +65,31 @@ totaleq_impl!(int)
65
65
totaleq_impl ! ( uint)
66
66
67
67
#[ deriving( Clone , Eq ) ]
68
- pub enum Ordering { Less , Equal , Greater }
68
+ pub enum Ordering { Less = - 1 , Equal = 0 , Greater = 1 }
69
69
70
70
/// Trait for types that form a total order
71
71
pub trait TotalOrd : TotalEq {
72
72
fn cmp ( & self , other : & Self ) -> Ordering ;
73
73
}
74
74
75
+ impl TotalOrd for Ordering {
76
+ #[ inline( always) ]
77
+ fn cmp ( & self , other : & Ordering ) -> Ordering {
78
+ ( * self as int ) . cmp ( & ( * other as int ) )
79
+ }
80
+ }
81
+
82
+ impl Ord for Ordering {
83
+ #[ inline( always) ]
84
+ fn lt ( & self , other : & Ordering ) -> bool { ( * self as int ) < ( * other as int ) }
85
+ #[ inline( always) ]
86
+ fn le ( & self , other : & Ordering ) -> bool { ( * self as int ) <= ( * other as int ) }
87
+ #[ inline( always) ]
88
+ fn gt ( & self , other : & Ordering ) -> bool { ( * self as int ) > ( * other as int ) }
89
+ #[ inline( always) ]
90
+ fn ge ( & self , other : & Ordering ) -> bool { ( * self as int ) >= ( * other as int ) }
91
+ }
92
+
75
93
macro_rules! totalord_impl(
76
94
( $t: ty) => {
77
95
impl TotalOrd for $t {
@@ -180,4 +198,10 @@ mod test {
180
198
assert ! ( 5 . equals( & 5 ) ) ;
181
199
assert ! ( !2 . equals( & 17 ) ) ;
182
200
}
201
+
202
+ #[ test]
203
+ fn test_ordering_order ( ) {
204
+ assert ! ( Less < Equal ) ;
205
+ assert_eq ! ( Greater . cmp( & Less ) , Greater ) ;
206
+ }
183
207
}
You can’t perform that action at this time.
0 commit comments