diff options
| author | Michael Sullivan <sully@msully.net> | 2013-07-19 15:21:52 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2013-07-23 17:06:32 -0700 |
| commit | a0f8540c9571dadb9af542799156cc8a96263c41 (patch) | |
| tree | 7a4cac0e0f300e5973de4865f31d7c30787c0e2e | |
| parent | e75ec8015701d4a43ec2644dbbc4a2e051c4f515 (diff) | |
Fix some impls such that all supertraits are actually implemented.
| -rw-r--r-- | src/libextra/num/bigint.rs | 5 | ||||
| -rw-r--r-- | src/libextra/num/rational.rs | 19 | ||||
| -rw-r--r-- | src/libstd/cmp.rs | 6 | ||||
| -rw-r--r-- | src/libstd/iterator.rs | 2 |
4 files changed, 31 insertions, 1 deletions
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index d940b6d6667..46a74457274 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -732,6 +732,11 @@ impl Ord for Sign { } } +impl TotalEq for Sign { + fn equals(&self, other: &Sign) -> bool { + *self == *other + } +} impl TotalOrd for Sign { fn cmp(&self, other: &Sign) -> Ordering { diff --git a/src/libextra/num/rational.rs b/src/libextra/num/rational.rs index 6733599d1ea..ff14009e556 100644 --- a/src/libextra/num/rational.rs +++ b/src/libextra/num/rational.rs @@ -110,6 +110,25 @@ cmp_impl!(impl TotalEq, equals) cmp_impl!(impl Ord, lt, gt, le, ge) cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering) +impl<T: Clone + Integer + Ord> Orderable for Ratio<T> { + #[inline] + fn min(&self, other: &Ratio<T>) -> Ratio<T> { + if *self < *other { self.clone() } else { other.clone() } + } + + #[inline] + fn max(&self, other: &Ratio<T>) -> Ratio<T> { + if *self > *other { self.clone() } else { other.clone() } + } + + #[inline] + fn clamp(&self, mn: &Ratio<T>, mx: &Ratio<T>) -> Ratio<T> { + if *self > *mx { mx.clone()} else + if *self < *mn { mn.clone() } else { self.clone() } + } +} + + /* Arithmetic */ // a/b * c/d = (a*c)/(b*d) impl<T: Clone + Integer + Ord> diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs index 8a13cab28c3..eee786524f5 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -86,6 +86,12 @@ pub trait TotalOrd: TotalEq { fn cmp(&self, other: &Self) -> Ordering; } +impl TotalEq for Ordering { + #[inline] + fn equals(&self, other: &Ordering) -> bool { + *self == *other + } +} impl TotalOrd for Ordering { #[inline] fn cmp(&self, other: &Ordering) -> Ordering { diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 1aca34894b4..d7edf746f90 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -86,7 +86,7 @@ impl<A, T: DoubleEndedIterator<A>> Iterator<A> for InvertIterator<A, T> { fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() } } -impl<A, T: Iterator<A>> DoubleEndedIterator<A> for InvertIterator<A, T> { +impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for InvertIterator<A, T> { #[inline] fn next_back(&mut self) -> Option<A> { self.iter.next() } } |
