Trait wyz::bidi::BidiIterator
source · pub trait BidiIteratorwhere
Self: Sized + IntoIterator,
<Self as IntoIterator>::IntoIter: DoubleEndedIterator,{
// Provided method
fn bidi(self, cond: bool) -> Bidi<Self::IntoIter> ⓘ { ... }
}
Expand description
Extension trait that provides .bidi()
for all double-ended iterators.
Provided Methods§
sourcefn bidi(self, cond: bool) -> Bidi<Self::IntoIter> ⓘ
fn bidi(self, cond: bool) -> Bidi<Self::IntoIter> ⓘ
Conditionally reverses the direction of iteration.
When cond
is true, this adapter swaps the next
and nth
methods
with next_back
and nth_back
. The resulting iterator is equivalent to
if cond { self.rev() } else { self }
.
Examples
use wyz::BidiIterator;
let data = [1, 2, 3];
let mut iter = data.iter().copied().bidi(false);
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next_back(), Some(3));
let mut iter = data.iter().copied().bidi(true);
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next_back(), Some(1));
Object Safety§
This trait is not object safe.