Trait itermap::IterMap [−][src]
pub trait IterMap<I, K, V>: Sized {
fn map_keys<Fk, J>(self, f: Fk) -> MapKeys<I, Fk>ⓘ
where
Fk: FnMut(K) -> J;
fn map_values<Fv, U>(self, f: Fv) -> MapValues<I, Fv>ⓘ
where
Fv: FnMut(V) -> U;
}Expand description
Adds additional methods for Iterators over maps (e.g., HashMap,
BTreeMap, etc.) and other two-element tuples (like (K, V)).
Required methods
Maps map keys (or the first element of a two-element tuple like
(K, V)), leaving other elements intact and untouched.
Example
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();Maps map values (or the second element of a two-element tuple like
(K, V)), leaving other elements intact and untouched.
Example
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();