Skip to content

Commit

Permalink
Merge pull request #15 from apasel422/untuck
Browse files Browse the repository at this point in the history
remove blanket impl for comparator references
  • Loading branch information
Gankra committed Apr 3, 2015
2 parents 34d1d4d + e722b60 commit 29ad2be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "compare"
version = "0.0.4"
version = "0.0.5"
license = "MIT/Apache-2.0"
description = "Experimental comparators for collections to be generic over"

Expand Down
14 changes: 3 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ use std::default::Default;
use std::marker::PhantomData;
use std::fmt::{self, Debug};

/// Returns the maximum of two values according to the given comparator, or `lhs` if they
/// Returns the maximum of two values according to the given comparator, or `rhs` if they
/// are equal.
///
/// # Examples
Expand All @@ -147,15 +147,15 @@ use std::fmt::{self, Debug};
/// let f3 = &Foo { key: 'b', id: 3};
///
/// let cmp = Extract::new(|f: &Foo| f.key, natural());
/// assert_eq!(max(&cmp, f1, f2).id, f1.id);
/// assert_eq!(max(&cmp, f1, f2).id, f2.id);
/// assert_eq!(max(&cmp, f1, f3).id, f3.id);
/// ```
// FIXME: convert to default method on `Compare` once where clauses permit equality
// (https://github.com/rust-lang/rust/issues/20041)
pub fn max<'a, C: ?Sized, T: ?Sized>(cmp: &C, lhs: &'a T, rhs: &'a T) -> &'a T
where C: Compare<T> {

if cmp.compares_ge(lhs, rhs) { lhs } else { rhs }
if cmp.compares_ge(rhs, lhs) { rhs } else { lhs }
}

/// Returns the minimum of two values according to the given comparator, or `lhs` if they
Expand Down Expand Up @@ -322,14 +322,6 @@ impl<F: ?Sized, Lhs: ?Sized, Rhs: ?Sized> Compare<Lhs, Rhs> for F
fn compare(&self, lhs: &Lhs, rhs: &Rhs) -> Ordering { (*self)(lhs, rhs) }
}

impl<'a, Lhs: ?Sized, Rhs: ?Sized, C: ?Sized> Compare<Lhs, Rhs> for &'a C
where C: Compare<Lhs, Rhs> {

fn compare(&self, lhs: &Lhs, rhs: &Rhs) -> Ordering {
Compare::compare(*self, lhs, rhs)
}
}

/// A comparator that borrows its parameters before comparing them.
///
/// See [`Compare::borrow`](trait.Compare.html#method.borrow) for an example.
Expand Down

0 comments on commit 29ad2be

Please sign in to comment.