Crate with_position [−] [src]
A Rust iterator extension trait to extend iterators with a new method called
with_position
which makes it easier to handle an element being the first,
last, middle or only element in an iteration. It is similar to a method in
itertools with the same name, but with a slightly different API, which IMO is
a bit easier to use.
Example
use with_position::{WithPosition, Position}; let result: Vec<_> = vec![1,2,3].into_iter().with_position().collect(); assert_eq!(result[0], (Position::First, 1)); assert_eq!(result[1], (Position::Middle, 2)); assert_eq!(result[2], (Position::Last, 3)); assert_eq!(result[0].0.is_first(), true); assert_eq!(result[1].0.is_first(), false);
Structs
PositionIterator |
An iterator adapter that yields tuples where the first element is a Position and the second is the item. |
Enums
Position |
An enum which indicates the position of an item in an iteration. |
Traits
WithPosition |
Extension trait for iterators which adds the |