Skip to content

Commit

Permalink
Fix some impls such that all supertraits are actually implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Jul 24, 2013
1 parent e75ec80 commit a0f8540
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions src/libextra/num/rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/libstd/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
Expand Down

0 comments on commit a0f8540

Please sign in to comment.