wyz::bidi

Trait BidiIterator

Source
pub trait BidiIterator{
    // Provided method
    fn bidi(self, cond: bool) -> Bidi<Self::IntoIter>  { ... }
}
Expand description

Extension trait that provides .bidi() for all double-ended iterators.

Provided Methods§

Source

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));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§