Skip to content

Commit

Permalink
core: Forward ExactSizeIterator methods for important iterator adaptors
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Nov 22, 2016
1 parent b1da18f commit 22739a1
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions src/libcore/iter/mod.rs
Expand Up @@ -368,7 +368,16 @@ impl<I> DoubleEndedIterator for Rev<I> where I: DoubleEndedIterator {

#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Rev<I>
where I: ExactSizeIterator + DoubleEndedIterator {}
where I: ExactSizeIterator + DoubleEndedIterator
{
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

#[unstable(feature = "fused", issue = "35602")]
impl<I> FusedIterator for Rev<I>
Expand Down Expand Up @@ -425,7 +434,15 @@ impl<'a, I, T: 'a> DoubleEndedIterator for Cloned<I>
#[stable(feature = "iter_cloned", since = "1.1.0")]
impl<'a, I, T: 'a> ExactSizeIterator for Cloned<I>
where I: ExactSizeIterator<Item=&'a T>, T: Clone
{}
{
fn len(&self) -> usize {
self.it.len()
}

fn is_empty(&self) -> bool {
self.it.is_empty()
}
}

#[unstable(feature = "fused", issue = "35602")]
impl<'a, I, T: 'a> FusedIterator for Cloned<I>
Expand Down Expand Up @@ -1007,7 +1024,16 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where

#[stable(feature = "rust1", since = "1.0.0")]
impl<B, I: ExactSizeIterator, F> ExactSizeIterator for Map<I, F>
where F: FnMut(I::Item) -> B {}
where F: FnMut(I::Item) -> B
{
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

#[unstable(feature = "fused", issue = "35602")]
impl<B, I: FusedIterator, F> FusedIterator for Map<I, F>
Expand Down Expand Up @@ -1236,7 +1262,15 @@ impl<I> DoubleEndedIterator for Enumerate<I> where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Enumerate<I> where I: ExactSizeIterator {}
impl<I> ExactSizeIterator for Enumerate<I> where I: ExactSizeIterator {
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

#[doc(hidden)]
unsafe impl<I> TrustedRandomAccess for Enumerate<I>
Expand Down Expand Up @@ -1927,7 +1961,15 @@ impl<I> DoubleEndedIterator for Fuse<I>


#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Fuse<I> where I: ExactSizeIterator {}
impl<I> ExactSizeIterator for Fuse<I> where I: ExactSizeIterator {
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

/// An iterator that calls a function with a reference to each element before
/// yielding it.
Expand Down Expand Up @@ -1994,7 +2036,16 @@ impl<I: DoubleEndedIterator, F> DoubleEndedIterator for Inspect<I, F>

#[stable(feature = "rust1", since = "1.0.0")]
impl<I: ExactSizeIterator, F> ExactSizeIterator for Inspect<I, F>
where F: FnMut(&I::Item) {}
where F: FnMut(&I::Item)
{
fn len(&self) -> usize {
self.iter.len()
}

fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

#[unstable(feature = "fused", issue = "35602")]
impl<I: FusedIterator, F> FusedIterator for Inspect<I, F>
Expand Down

0 comments on commit 22739a1

Please sign in to comment.