iter-index

Crates.ioiter-index
lib.rsiter-index
version
sourcesrc
created_at2025-01-17 20:16:58.03006+00
updated_at2025-05-07 19:06:45.206234+00
descriptionMore flexible alternative to Iterator's enumerate() method
homepagehttps://github.com/blueglyph/iter_index
repositoryhttps://github.com/blueglyph/iter_index
max_upload_size
id1520957
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Redglyph (blueglyph)

documentation

https://docs.rs/iter-index

README

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.

Commit count: 10

cargo fmt