iterator_to_hash_map 0.9.0

A Rust crate that adds a method to any `Iterator` or `IntoIterator` (such as `Vec`) that converts it to a `HashMap` using the trait `ToHashMap`.
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 4.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • bradurani/rust-iterator-to-hash-map
    6 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bradurani

Iterator to HashMap

A Rust crate that adds a method to any Iterator or IntoIterator (such as Vec) that converts it to a HashMap using the trait ToHashMap.

extern crate iterator_to_hash_map;

use std::collections::HashMap;
use iterator_to_hash_map::ToHashMap;

struct Person {
    id: i32,
    first_name: &'static str,
    last_name: &'static str,
}

let brad = Person {
    id: 1,
    first_name: "Brad",
    last_name: "Urani",
};

let barb = Person {
    id: 2,
    first_name: "Barb",
    last_name: "Hanover",
};

let a = vec![brad, barb];
let key_func = |i: &Person| -> i32 { i.id };
let value_func = |i: &Person| -> String {
    i.first_name.to_string() + &" " + &i.last_name.to_string()
};

let map = a.to_hash_map(key_func, value_func);
# { 1: "Brad Urani", 2: "Barb Hanover" }

Contributing

Open a pull request!