From a32ffc679702e3ae307c7fc20873c9e970a8894c Mon Sep 17 00:00:00 2001 From: Nick Whitney Date: Tue, 6 Jun 2017 23:00:09 -0400 Subject: [PATCH] Alias std::cmp::max/min to Ord::max/min --- src/libcore/cmp.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 4c50b11e7050..6f35d0417f18 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -714,6 +714,8 @@ pub trait PartialOrd: PartialEq { /// /// Returns the first argument if the comparison determines them to be equal. /// +/// Internally uses an alias to `Ord::min`. +/// /// # Examples /// /// ``` @@ -725,13 +727,15 @@ pub trait PartialOrd: PartialEq { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn min(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 /// /// ``` @@ -743,7 +747,7 @@ pub fn min(v1: T, v2: T) -> T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn max(v1: T, v2: T) -> T { - if v2 >= v1 { v2 } else { v1 } + v1.max(v2) } // Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types