[go: up one dir, main page]

Function max

Source
pub fn max<'a, C, T: ?Sized>(cmp: &C, l: &'a T, r: &'a T) -> &'a T
where C: Compare<T> + ?Sized,
Expand description

Returns the maximum of two values according to the given comparator, or r if they are equal.

ยงExamples

use compare::{Extract, max};

struct Foo { key: char, id: u8 }

let f1 = &Foo { key: 'a', id: 1};
let f2 = &Foo { key: 'a', id: 2};
let f3 = &Foo { key: 'b', id: 3};

let cmp = Extract::new(|f: &Foo| f.key);
assert_eq!(max(&cmp, f1, f2).id, f2.id);
assert_eq!(max(&cmp, f1, f3).id, f3.id);