]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/cmp.rs
Alias std::cmp::max/min to Ord::max/min
[rust.git] / src / libcore / cmp.rs
index 4c50b11e70507ba53599b3c720b79dcd66829384..6f35d0417f18b1986f6db9042df62c09b625fa2b 100644 (file)
@@ -714,6 +714,8 @@ fn ge(&self, other: &Rhs) -> bool {
 ///
 /// Returns the first argument if the comparison determines them to be equal.
 ///
+/// Internally uses an alias to `Ord::min`.
+///
 /// # Examples
 ///
 /// ```
@@ -725,13 +727,15 @@ fn ge(&self, other: &Rhs) -> bool {
 #[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
 ///
 /// ```
@@ -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