Skip to content

Commit 88620c2

Browse files
committed
std: implement Total{Ord,Eq} for pointers.
1 parent 8407ec9 commit 88620c2

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/libstd/borrow.rs

+12
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,15 @@ impl<'self, T: Ord> Ord for &'self T {
5858
*(*self) > *(*other)
5959
}
6060
}
61+
62+
#[cfg(not(test))]
63+
impl<'self, T: TotalOrd> TotalOrd for &'self T {
64+
#[inline]
65+
fn cmp(&self, other: & &'self T) -> Ordering { (**self).cmp(*other) }
66+
}
67+
68+
#[cfg(not(test))]
69+
impl<'self, T: TotalEq> TotalEq for &'self T {
70+
#[inline]
71+
fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
72+
}

src/libstd/managed.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use ptr::to_unsafe_ptr;
1414

15-
#[cfg(not(test))] use cmp::{Eq, Ord};
15+
#[cfg(not(test))] use cmp::*;
1616

1717
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
1818
pub static RC_IMMORTAL : uint = 0x77777777;
@@ -71,6 +71,29 @@ impl<T:Ord> Ord for @mut T {
7171
fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
7272
}
7373

74+
#[cfg(not(test))]
75+
impl<T: TotalOrd> TotalOrd for @T {
76+
#[inline]
77+
fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) }
78+
}
79+
80+
#[cfg(not(test))]
81+
impl<T: TotalOrd> TotalOrd for @mut T {
82+
#[inline]
83+
fn cmp(&self, other: &@mut T) -> Ordering { (**self).cmp(*other) }
84+
}
85+
86+
#[cfg(not(test))]
87+
impl<T: TotalEq> TotalEq for @T {
88+
#[inline]
89+
fn equals(&self, other: &@T) -> bool { (**self).equals(*other) }
90+
}
91+
92+
#[cfg(not(test))]
93+
impl<T: TotalEq> TotalEq for @mut T {
94+
#[inline]
95+
fn equals(&self, other: &@mut T) -> bool { (**self).equals(*other) }
96+
}
7497
#[test]
7598
fn test() {
7699
let x = @3;

src/libstd/owned.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Operations on unique pointer types
1212
13-
#[cfg(not(test))] use cmp::{Eq, Ord};
13+
#[cfg(not(test))] use cmp::*;
1414

1515
#[cfg(not(test))]
1616
impl<T:Eq> Eq for ~T {
@@ -31,3 +31,15 @@ impl<T:Ord> Ord for ~T {
3131
#[inline]
3232
fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
3333
}
34+
35+
#[cfg(not(test))]
36+
impl<T: TotalOrd> TotalOrd for ~T {
37+
#[inline]
38+
fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) }
39+
}
40+
41+
#[cfg(not(test))]
42+
impl<T: TotalEq> TotalEq for ~T {
43+
#[inline]
44+
fn equals(&self, other: &~T) -> bool { (**self).equals(*other) }
45+
}

0 commit comments

Comments
 (0)