use std::collections::HashMap; fn main() { let text = String::from("aa bb cc d aa c c"); let mut m: HashMap<&str, i32> = HashMap::new(); for w in text.split_whitespace() { let c = m.entry(w).or_insert(0); *c += 1; } println!("{:?}", m); }