IndexerIterator

Trait IndexerIterator 

Source
pub trait IndexerIterator {
    // Provided methods
    fn index<T>(self) -> Indexer<Self, T> 
       where Self: Sized,
             u8: Into<T> { ... }
    fn index_start<T>(self, start: T) -> Indexer<Self, T> 
       where Self: Sized,
             u8: Into<T> { ... }
    fn index_step<T>(self, start: T, step: T) -> Indexer<Self, T> 
       where Self: Sized { ... }
}

Provided Methods§

Source

fn index<T>(self) -> Indexer<Self, T>
where Self: Sized, u8: Into<T>,

Creates an iterator which gives an index of the source iterator value as well as the value itself.

The iterator yields pairs (i, val), where i is of type T and contains the current index of iteration, and val is the value returned by the source iterator.

index::<T>() starts counting at 0 and increments by 1. If you need another start value, use index_start::<T>(start: T) instead. If you need different steps than 1, use index_step::<T>(start: T, step: T).

§Overflow Behavior

The method does no guarding against overflows, so you may have to prevent it, depending on the type T and the number of items generated by the source iterator.

§Examples
use iter_index::IndexerIterator;

let items = vec!["a", "b", "c"];
let mut result = items.into_iter().index::<i32>();

assert_eq!(result.next(), Some((0_i32, "a")));
assert_eq!(result.next(), Some((1_i32, "b")));
assert_eq!(result.next(), Some((2_i32, "c")));
assert_eq!(result.next(), None);
Source

fn index_start<T>(self, start: T) -> Indexer<Self, T>
where Self: Sized, u8: Into<T>,

Creates an iterator which gives an index of the source iterator value as well as the value itself.

The iterator yields pairs (i, val), where i is of type T and contains the current index of iteration, and val is the value returned by the source iterator.

index_start::<T>(start: T) starts counting at start and increments by 1. If you need different steps than 1, use index_step::<T>(start: T, step: T).

§Overflow Behavior

The method does no guarding against overflows, so you may have to prevent it, depending on the type T and the number of items generated by the source iterator.

§Examples
use iter_index::IndexerIterator;

let items = vec!["a", "b", "c"];
let mut result = items.into_iter().index_start::<u8>(97);

assert_eq!(result.next(), Some((97_u8, "a")));
assert_eq!(result.next(), Some((98_u8, "b")));
assert_eq!(result.next(), Some((99_u8, "c")));
assert_eq!(result.next(), None);
Source

fn index_step<T>(self, start: T, step: T) -> Indexer<Self, T>
where Self: Sized,

Creates an iterator which gives an index of the source iterator value as well as the value itself.

The iterator yields pairs (i, val), where i is of type T and contains the current index of iteration, and val is the value returned by the source iterator.

index_step::<T>(start: T, step: T) starts counting at start and increments by step.

§Overflow Behavior

The method does no guarding against overflows, so you may have to prevent it, depending on the type T and the number of items generated by the source iterator.

§Examples
use iter_index::IndexerIterator;

let items = vec!["a", "b", "c"];
let mut result = items.into_iter().index_step::<u32>(100, 10);

assert_eq!(result.next(), Some((100_u32, "a")));
assert_eq!(result.next(), Some((110_u32, "b")));
assert_eq!(result.next(), Some((120_u32, "c")));
assert_eq!(result.next(), None);

Implementors§