| 1 |
#[lang = "sized"] |
| 2 |
pub trait Sized { |
| 3 |
// Empty. |
| 4 |
} |
| 5 |
|
| 6 |
#[lang = "fn_once"] |
| 7 |
pub trait FnOnce<Args> { |
| 8 |
/// The returned type after the call operator is used. |
| 9 |
#[lang = "fn_once_output"] |
| 10 |
type Output; |
| 11 |
|
| 12 |
/// Performs the call operation. |
| 13 |
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; |
| 14 |
} |
| 15 |
|
| 16 |
pub enum Ordering { |
| 17 |
/// An ordering where a compared value is less than another. |
| 18 |
Less = -1, |
| 19 |
/// An ordering where a compared value is equal to another. |
| 20 |
Equal = 0, |
| 21 |
/// An ordering where a compared value is greater than another. |
| 22 |
Greater = 1, |
| 23 |
} |
| 24 |
|
| 25 |
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T { |
| 26 |
match compare(&v1, &v2) { |
| 27 |
Ordering::Less | Ordering::Equal => v2, |
| 28 |
Ordering::Greater => v1, |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T { |
| 33 |
match compare(&v1, &v2) { |
| 34 |
Ordering::Less | Ordering::Equal => v1, |
| 35 |
Ordering::Greater => v2, |
| 36 |
} |
| 37 |
} |