iter-index 1.0.0

More flexible alternative to Iterator's enumerate() method
Documentation
  • Coverage
  • 71.43%
    5 out of 7 items documented4 out of 7 items with examples
  • Size
  • Source code size: 26.71 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 563.65 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • blueglyph/iter_index
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • blueglyph

crate documentation license license

iter-index crate

This is a simple extension trait that provides a more flexible alternative to the iterator's method enumerate(). It allows to:

  • use a custom type for the index with index::<T>()
  • define a custom start value with index_start::<T>(start: T)
  • define a custom step value with index_step::<T>(start: T, step: T).

Examples

use iter_index::IndexerIterator;

let mut map = HashMap::<u8, &str>::new();
for (k, v) in vec!["a", "b", "c"].into_iter().index() {
    map.insert(k, v);
}
assert_eq!(map, HashMap::from([(0_u8, "a"), (1_u8, "b"), (2_u8, "c")]));
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);
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);

License

This code is licensed under either MIT License or Apache License 2.0.