Trait splop::IterStatusExt [−][src]
pub trait IterStatusExt: Iterator + Sized { fn with_status(self) -> WithStatus<Self>; }
Adds the with_status
method to all iterators.
Required Methods
ⓘImportant traits for WithStatus<I>
fn with_status(self) -> WithStatus<Self>
Creates an iterator that yields the original items paired with a status, which tells you if the item is the first and/or last one.
The new iterator's item has the type (Self::Item, Status)
. See
Status
for detailed information. The new iterator uses peekable()
internally, so if the next()
call of the underlying iterator has
side effects, those will be visible earlier than expected.
Example
use splop::IterStatusExt; let mut s = String::new(); let names = ["anna", "peter", "bob"]; for (name, status) in names.iter().with_status() { if !status.is_first() { s += ", "; } s += name; } assert_eq!(s, "anna, peter, bob");
Implementors
impl<I: Iterator> IterStatusExt for I