Skip to content

Commit

Permalink
Add FusedIterator for which it is commented fused.
Browse files Browse the repository at this point in the history
Interleave, IntersperseWith, and ZipLongest are said to be fused,
but it wasn't marked as FusedIterator.
  • Loading branch information
aobatact committed May 25, 2021
1 parent a9e367f commit 4f4230f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/adaptors/mod.rs
Expand Up @@ -15,7 +15,7 @@ pub use self::map::MapResults;
pub use self::multi_product::*;

use std::fmt;
use std::iter::{Fuse, Peekable, FromIterator};
use std::iter::{Fuse, Peekable, FromIterator, FusedIterator};
use std::marker::PhantomData;
use crate::size_hint;

Expand Down Expand Up @@ -75,6 +75,11 @@ impl<I, J> Iterator for Interleave<I, J>
}
}

impl<I, J> FusedIterator for Interleave<I, J>
where I: Iterator,
J: Iterator<Item = I::Item>
{}

/// An iterator adaptor that alternates elements from the two iterators until
/// one of them runs out.
///
Expand Down
7 changes: 6 additions & 1 deletion src/intersperse.rs
@@ -1,4 +1,4 @@
use std::iter::Fuse;
use std::iter::{Fuse, FusedIterator};
use super::size_hint;

pub trait IntersperseElement<Item> {
Expand Down Expand Up @@ -112,3 +112,8 @@ impl<I, ElemF> Iterator for IntersperseWith<I, ElemF>
})
}
}

impl<I, ElemF> FusedIterator for IntersperseWith<I, ElemF>
where I: Iterator,
ElemF: IntersperseElement<I::Item>
{}
7 changes: 6 additions & 1 deletion src/zip_longest.rs
@@ -1,6 +1,6 @@
use std::cmp::Ordering::{Equal, Greater, Less};
use super::size_hint;
use std::iter::Fuse;
use std::iter::{Fuse, FusedIterator};

use crate::either_or_both::EitherOrBoth;

Expand Down Expand Up @@ -76,3 +76,8 @@ impl<T, U> ExactSizeIterator for ZipLongest<T, U>
where T: ExactSizeIterator,
U: ExactSizeIterator
{}

impl<T, U> FusedIterator for ZipLongest<T, U>
where T: Iterator,
U: Iterator
{}

0 comments on commit 4f4230f

Please sign in to comment.