Function compare::min
[−]
[src]
pub fn min<'a, C: ?Sized, T: ?Sized>(cmp: &C, l: &'a T, r: &'a T) -> &'a T where C: Compare<T>
Returns the minimum of two values according to the given comparator, or l
if they
are equal.
Examples
use compare::{Extract, min}; struct Foo { key: char, id: u8 } let f1 = &Foo { key: 'b', id: 1}; let f2 = &Foo { key: 'b', id: 2}; let f3 = &Foo { key: 'a', id: 3}; let cmp = Extract::new(|f: &Foo| f.key); assert_eq!(min(&cmp, f1, f2).id, f1.id); assert_eq!(min(&cmp, f1, f3).id, f3.id);