@@ -218,6 +218,15 @@ impl<T> [T] {
218218 /// * total and antisymmetric: exactly one of a < b, a == b or a > b is true; and
219219 /// * transitive, a < b and b < c implies a < c. The same must hold for both == and >.
220220 ///
221+ /// For example, while `f64` doesn't implement `Ord` because `NaN != NaN`, we can use
222+ /// `partial_cmp` as our sort function when we know the slice doesn't contain a `NaN`.
223+ ///
224+ /// ```
225+ /// let mut floats = [5f64, 4.0, 1.0, 3.0, 2.0];
226+ /// floats.sort_by(|a, b| a.partial_cmp(b).unwrap());
227+ /// assert_eq!(floats, [1.0, 2.0, 3.0, 4.0, 5.0]);
228+ /// ```
229+ ///
221230 /// When applicable, unstable sorting is preferred because it is generally faster than stable
222231 /// sorting and it doesn't allocate auxiliary memory.
223232 /// See [`sort_unstable_by`](#method.sort_unstable_by).
@@ -242,12 +251,6 @@ impl<T> [T] {
242251 /// // reverse sorting
243252 /// v.sort_by(|a, b| b.cmp(a));
244253 /// assert!(v == [5, 4, 3, 2, 1]);
245- ///
246- /// // While f64 doesn't implement Ord because NaN != NaN, we can use
247- /// // partial_cmp here because we know none of the elements are NaN.
248- /// let mut floats = [5f64, 4.0, 1.0, 3.0, 2.0];
249- /// floats.sort_by(|a, b| a.partial_cmp(b).unwrap());
250- /// assert_eq!(floats, [1.0, 2.0, 3.0, 4.0, 5.0]);
251254 /// ```
252255 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
253256 #[ inline]
0 commit comments