Skip to content

Commit

Permalink
Alias std::cmp::max/min to Ord::max/min
Browse files Browse the repository at this point in the history
  • Loading branch information
Razaekel committed Jun 7, 2017
1 parent 2cadc32 commit a32ffc6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libcore/cmp.rs
Expand Up @@ -714,6 +714,8 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
///
/// Returns the first argument if the comparison determines them to be equal.
///
/// Internally uses an alias to `Ord::min`.
///
/// # Examples
///
/// ```
Expand All @@ -725,13 +727,15 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn min<T: Ord>(v1: T, v2: T) -> T {
if v1 <= v2 { v1 } else { v2 }
v1.min(v2)
}

/// Compares and returns the maximum of two values.
///
/// Returns the second argument if the comparison determines them to be equal.
///
/// Internally uses an alias to `Ord::max`.
///
/// # Examples
///
/// ```
Expand All @@ -743,7 +747,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn max<T: Ord>(v1: T, v2: T) -> T {
if v2 >= v1 { v2 } else { v1 }
v1.max(v2)
}

// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
Expand Down

0 comments on commit a32ffc6

Please sign in to comment.