Crate itermap[−][src]
Expand description
Tools for Iterator
s over maps (HashMap
, BTreeMap
, etc),
or any two-element tuple.
Just import IterMap
to get extra methods on iterators.
Examples
Mapping keys:
use itermap::IterMap;
let mut hash: HashMap<&str, &str> = HashMap::new();
hash.insert("a", "A");
hash.insert("b", "B");
let hash: HashMap<String, &str> = hash
.into_iter()
.map_keys(String::from)
.collect();
Mapping values:
use itermap::IterMap;
let mut hash: HashMap<&str, &str> = HashMap::new();
hash.insert("a", "A");
hash.insert("b", "B");
let hash: HashMap<&str, String> = hash
.into_iter()
.map_values(String::from)
.collect();
You can, of course, chain both adaptors to map both keys and values:
use itermap::IterMap;
let mut hash: HashMap<&str, &str> = HashMap::new();
hash.insert("a", "A");
hash.insert("b", "B");
let hash: HashMap<String, char> = hash
.into_iter()
.map_keys(String::from)
.map_values(|v| v.parse().unwrap())
.collect();
It works with any iterator over a two-element tuple:
use itermap::IterMap;
let mut values: Vec<(&str, &str)> = Vec::new();
values.push(("a", "A"));
values.push(("b", "B"));
let values: Vec<(String, char)> = values
.into_iter()
.map_keys(String::from)
.map_values(|v| v.parse().unwrap())
.collect();
Structs
Maps keys (or the first element of a two-element tuple like (K, V)
),
leaving other elements intact and untouched.
Maps values (or the second element of a two-element tuple like (K, V)
),
leaving other elements intact and untouched.
Traits
Adds additional methods for Iterator
s over maps (e.g., HashMap
,
BTreeMap
, etc.) and other two-element tuples (like (K, V)
).