#hash-map #map

hashmap_to_hashmap

Adds a method .map to HashMap that maps to another HashMap

1 unstable release

Uses old Rust 2015

0.9.0 Jan 20, 2016

#21 in #hashmap

MIT license

3KB

HashMap to HashMap

Adds a method .map to HashMap that maps to another HashMap


        let brad = Person {
            id: 1,
            first_name: "Brad",
            last_name: "Urani",
        };
        let susan = Person {
            id: 2,
            first_name: "Susan",
            last_name: "Urani",
        };
        let mut h: HashMap<i32, Person> = HashMap::new();
        h.insert(12, brad);
        h.insert(29, susan);

        let new_map = h.map(|k, v| v.id,
                            |k, v| k.to_string() + &"-" + &v.first_name + &" " + &v.last_name);
        // { 1: "12-Brad Urani", 2: "29-Susan Urani" }

No runtime deps