diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-30 22:00:31 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-07 08:15:58 -0700 |
| commit | c5229e5d2ea6168ec80a7feeea1a513b2b3176c0 (patch) | |
| tree | 479726fbafd85d1dd0549e3707882d44ea4dfd74 /src/libcore/cmp.rs | |
| parent | 5592a8f5db52a11b63547b661b3a635655b16980 (diff) | |
| download | rust-c5229e5d2ea6168ec80a7feeea1a513b2b3176c0.tar.gz rust-c5229e5d2ea6168ec80a7feeea1a513b2b3176c0.zip | |
core: Inhert ~/@/& cmp traits, remove old modules
This commit removes the std::{managed, reference} modules. The modules serve
essentially no purpose, and the only free function removed was `managed::ptr_eq`
which can be achieved by comparing references.
[breaking-change]
Diffstat (limited to 'src/libcore/cmp.rs')
| -rw-r--r-- | src/libcore/cmp.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 867871805d0..0ad2a465522 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -189,6 +189,81 @@ pub fn max<T: TotalOrd>(v1: T, v2: T) -> T { if v1 > v2 { v1 } else { v2 } } +// Implementation of Eq/TotalEq for some primitive types +#[cfg(not(test))] +mod impls { + use cmp::{Ord, TotalOrd, Eq, TotalEq, Ordering}; + + // & pointers + impl<'a, T: Eq> Eq for &'a T { + #[inline] + fn eq(&self, other: & &'a T) -> bool { *(*self) == *(*other) } + #[inline] + fn ne(&self, other: & &'a T) -> bool { *(*self) != *(*other) } + } + impl<'a, T: Ord> Ord for &'a T { + #[inline] + fn lt(&self, other: & &'a T) -> bool { *(*self) < *(*other) } + #[inline] + fn le(&self, other: & &'a T) -> bool { *(*self) <= *(*other) } + #[inline] + fn ge(&self, other: & &'a T) -> bool { *(*self) >= *(*other) } + #[inline] + fn gt(&self, other: & &'a T) -> bool { *(*self) > *(*other) } + } + impl<'a, T: TotalOrd> TotalOrd for &'a T { + #[inline] + fn cmp(&self, other: & &'a T) -> Ordering { (**self).cmp(*other) } + } + impl<'a, T: TotalEq> TotalEq for &'a T {} + + // @ pointers + impl<T:Eq> Eq for @T { + #[inline] + fn eq(&self, other: &@T) -> bool { *(*self) == *(*other) } + #[inline] + fn ne(&self, other: &@T) -> bool { *(*self) != *(*other) } + } + impl<T:Ord> Ord for @T { + #[inline] + fn lt(&self, other: &@T) -> bool { *(*self) < *(*other) } + #[inline] + fn le(&self, other: &@T) -> bool { *(*self) <= *(*other) } + #[inline] + fn ge(&self, other: &@T) -> bool { *(*self) >= *(*other) } + #[inline] + fn gt(&self, other: &@T) -> bool { *(*self) > *(*other) } + } + impl<T: TotalOrd> TotalOrd for @T { + #[inline] + fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) } + } + impl<T: TotalEq> TotalEq for @T {} + + // ~ pointers + impl<T:Eq> Eq for ~T { + #[inline] + fn eq(&self, other: &~T) -> bool { *(*self) == *(*other) } + #[inline] + fn ne(&self, other: &~T) -> bool { *(*self) != *(*other) } + } + impl<T:Ord> Ord for ~T { + #[inline] + fn lt(&self, other: &~T) -> bool { *(*self) < *(*other) } + #[inline] + fn le(&self, other: &~T) -> bool { *(*self) <= *(*other) } + #[inline] + fn ge(&self, other: &~T) -> bool { *(*self) >= *(*other) } + #[inline] + fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) } + } + impl<T: TotalOrd> TotalOrd for ~T { + #[inline] + fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) } + } + impl<T: TotalEq> TotalEq for ~T {} +} + #[cfg(test)] mod test { use super::lexical_ordering; |
