@@ -3475,8 +3475,10 @@ pub trait Iterator {
3475
3475
}
3476
3476
}
3477
3477
3478
- /// [Lexicographically](Ord#lexicographical-comparison) compares the elements of this [`Iterator`] with those
3479
- /// of another.
3478
+ /// [Lexicographically](Ord#lexicographical-comparison) compares the [`PartialOrd`] elements of
3479
+ /// this [`Iterator`] with those of another. The comparison works like short-circuit
3480
+ /// evaluation, returning a result without comparing the remaining elements.
3481
+ /// As soon as an order can be determined, the evaluation stops and a result is returned.
3480
3482
///
3481
3483
/// # Examples
3482
3484
///
@@ -3486,9 +3488,25 @@ pub trait Iterator {
3486
3488
/// assert_eq!([1.].iter().partial_cmp([1.].iter()), Some(Ordering::Equal));
3487
3489
/// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less));
3488
3490
/// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater));
3491
+ /// ```
3489
3492
///
3493
+ /// For floating-point numbers, NaN does not have a total order and will result
3494
+ /// in `None` when compared:
3495
+ ///
3496
+ /// ```
3490
3497
/// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None);
3491
3498
/// ```
3499
+ ///
3500
+ /// The results are determined by the order of evaluation.
3501
+ ///
3502
+ /// ```
3503
+ /// use std::cmp::Ordering;
3504
+ ///
3505
+ /// assert_eq!([1.0, f64::NAN].iter().partial_cmp([2.0, f64::NAN].iter()), Some(Ordering::Less));
3506
+ /// assert_eq!([2.0, f64::NAN].iter().partial_cmp([1.0, f64::NAN].iter()), Some(Ordering::Greater));
3507
+ /// assert_eq!([f64::NAN, 1.0].iter().partial_cmp([f64::NAN, 2.0].iter()), None);
3508
+ /// ```
3509
+ ///
3492
3510
#[ stable( feature = "iter_order" , since = "1.5.0" ) ]
3493
3511
fn partial_cmp < I > ( self , other : I ) -> Option < Ordering >
3494
3512
where
0 commit comments