Skip to content

remove blanket impl for comparator references #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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