@@ -1087,6 +1087,12 @@ impl<'a, I> DoubleEndedIterator for ByRef<'a, I> where I: 'a + DoubleEndedIterat
1087
1087
fn next_back ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next_back ( ) }
1088
1088
}
1089
1089
1090
+ #[ stable]
1091
+ impl < ' a , I > ExactSizeIterator for ByRef < ' a , I > where I : ' a + ExactSizeIterator {
1092
+ #[ inline]
1093
+ fn len ( & self ) -> uint { self . iter . len ( ) }
1094
+ }
1095
+
1090
1096
/// A trait for iterators over elements which can be added together
1091
1097
#[ unstable = "needs to be re-evaluated as part of numerics reform" ]
1092
1098
pub trait AdditiveIterator < A > {
@@ -1790,6 +1796,16 @@ impl<T, I> Iterator for Peekable<T, I> where I: Iterator<Item=T> {
1790
1796
}
1791
1797
}
1792
1798
1799
+ #[ stable]
1800
+ impl < T , I > ExactSizeIterator for Peekable < T , I > where I : ExactSizeIterator < Item = T > {
1801
+ #[ inline]
1802
+ fn len ( & self ) -> usize {
1803
+ // This is guarenteed to not overflow because `len()` must have been able to return a valid
1804
+ // value before we peeked.
1805
+ self . iter . len ( ) + if self . peeked . is_some ( ) { 1 } else { 0 }
1806
+ }
1807
+ }
1808
+
1793
1809
#[ stable]
1794
1810
impl < T , I > Peekable < T , I > where I : Iterator < Item =T > {
1795
1811
/// Return a reference to the next element of the iterator with out advancing it,
@@ -1982,6 +1998,12 @@ impl<I> RandomAccessIterator for Skip<I> where I: RandomAccessIterator{
1982
1998
}
1983
1999
}
1984
2000
2001
+ #[ stable]
2002
+ impl < I > ExactSizeIterator for Skip < I > where I : ExactSizeIterator {
2003
+ #[ inline]
2004
+ fn len ( & self ) -> uint { self . iter . len ( ) . saturating_sub ( self . n ) }
2005
+ }
2006
+
1985
2007
/// An iterator that only iterates over the first `n` iterations of `iter`.
1986
2008
#[ derive( Clone ) ]
1987
2009
#[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
@@ -2037,6 +2059,12 @@ impl<I> RandomAccessIterator for Take<I> where I: RandomAccessIterator{
2037
2059
}
2038
2060
}
2039
2061
2062
+ #[ stable]
2063
+ impl < I > ExactSizeIterator for Take < I > where I : ExactSizeIterator {
2064
+ #[ inline]
2065
+ fn len ( & self ) -> uint { cmp:: min ( self . iter . len ( ) , self . n ) }
2066
+ }
2067
+
2040
2068
2041
2069
/// An iterator to maintain state while iterating another iterator
2042
2070
#[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
@@ -2246,6 +2274,12 @@ impl<I> RandomAccessIterator for Fuse<I> where I: RandomAccessIterator {
2246
2274
}
2247
2275
}
2248
2276
2277
+ #[ stable]
2278
+ impl < I > ExactSizeIterator for Fuse < I > where I : ExactSizeIterator {
2279
+ #[ inline]
2280
+ fn len ( & self ) -> uint { self . iter . len ( ) }
2281
+ }
2282
+
2249
2283
impl < I > Fuse < I > {
2250
2284
/// Resets the fuse such that the next call to .next() or .next_back() will
2251
2285
/// call the underlying iterator again even if it previously returned None.
0 commit comments