Skip to content

Commit a32ffc6

Browse files
committed
Alias std::cmp::max/min to Ord::max/min
1 parent 2cadc32 commit a32ffc6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/libcore/cmp.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
714714
///
715715
/// Returns the first argument if the comparison determines them to be equal.
716716
///
717+
/// Internally uses an alias to `Ord::min`.
718+
///
717719
/// # Examples
718720
///
719721
/// ```
@@ -725,13 +727,15 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
725727
#[inline]
726728
#[stable(feature = "rust1", since = "1.0.0")]
727729
pub fn min<T: Ord>(v1: T, v2: T) -> T {
728-
if v1 <= v2 { v1 } else { v2 }
730+
v1.min(v2)
729731
}
730732

731733
/// Compares and returns the maximum of two values.
732734
///
733735
/// Returns the second argument if the comparison determines them to be equal.
734736
///
737+
/// Internally uses an alias to `Ord::max`.
738+
///
735739
/// # Examples
736740
///
737741
/// ```
@@ -743,7 +747,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
743747
#[inline]
744748
#[stable(feature = "rust1", since = "1.0.0")]
745749
pub fn max<T: Ord>(v1: T, v2: T) -> T {
746-
if v2 >= v1 { v2 } else { v1 }
750+
v1.max(v2)
747751
}
748752

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

0 commit comments

Comments
 (0)