Skip to content

Commit aa197e1

Browse files
committed
---
yaml --- r: 57311 b: refs/heads/incoming c: a3f4018 h: refs/heads/master i: 57309: 2a9a0ef 57307: 62c2dfb 57303: f900df3 57295: 6b99f3e 57279: 828689b v: v3
1 parent d767e3d commit aa197e1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: bf67eb2362b7d0f37012f2d6dac604c3bbacd2c6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: c47d80304e7b3726352183f466ab0756c24d7431
9+
refs/heads/incoming: a3f40184bdc0d094ac76b15f66bfbf87a699a705
1010
refs/heads/dist-snap: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/cmp.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,31 @@ totaleq_impl!(int)
6565
totaleq_impl!(uint)
6666

6767
#[deriving(Clone, Eq)]
68-
pub enum Ordering { Less, Equal, Greater }
68+
pub enum Ordering { Less = -1, Equal = 0, Greater = 1 }
6969

7070
/// Trait for types that form a total order
7171
pub trait TotalOrd: TotalEq {
7272
fn cmp(&self, other: &Self) -> Ordering;
7373
}
7474

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+
7593
macro_rules! totalord_impl(
7694
($t:ty) => {
7795
impl TotalOrd for $t {
@@ -180,4 +198,10 @@ mod test {
180198
assert!(5.equals(&5));
181199
assert!(!2.equals(&17));
182200
}
201+
202+
#[test]
203+
fn test_ordering_order() {
204+
assert!(Less < Equal);
205+
assert_eq!(Greater.cmp(&Less), Greater);
206+
}
183207
}

0 commit comments

Comments
 (0)