@@ -485,8 +485,6 @@ impl<'a, I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for &'a mut I {
485
485
/// ```
486
486
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
487
487
pub trait ExactSizeIterator : Iterator {
488
- #[ inline]
489
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
490
488
/// Returns the exact number of times the iterator will iterate.
491
489
///
492
490
/// This method has a default implementation, so you usually should not
@@ -510,6 +508,8 @@ pub trait ExactSizeIterator: Iterator {
510
508
///
511
509
/// assert_eq!(5, five.len());
512
510
/// ```
511
+ #[ inline]
512
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
513
513
fn len ( & self ) -> usize {
514
514
let ( lower, upper) = self . size_hint ( ) ;
515
515
// Note: This assertion is overly defensive, but it checks the invariant
@@ -519,6 +519,31 @@ pub trait ExactSizeIterator: Iterator {
519
519
assert_eq ! ( upper, Some ( lower) ) ;
520
520
lower
521
521
}
522
+
523
+ ///
524
+ /// Returns whether the iterator is empty.
525
+ ///
526
+ /// This method has a default implementation using `self.len()`, so you
527
+ /// don't need to implement it yourself.
528
+ ///
529
+ /// # Examples
530
+ ///
531
+ /// Basic usage:
532
+ ///
533
+ /// ```
534
+ /// let mut one_element = [0].iter();
535
+ /// assert!(!one_element.is_empty());
536
+ ///
537
+ /// assert_eq!(one_element.next(), Some(0));
538
+ /// assert!(one_element.is_empty());
539
+ ///
540
+ /// assert_eq!(one_element.next(), None);
541
+ /// ```
542
+ #[ inline]
543
+ #[ unstable( feature = "exact_size_is_empty" , issue = "0" ) ]
544
+ fn is_empty ( & self ) -> bool {
545
+ self . len ( ) == 0
546
+ }
522
547
}
523
548
524
549
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments