fn main() { use std::collections::HashMap; let text = "the quick brown fox jumps over the lazy dog the fox"; let mut counts: HashMap<&str, i32> = HashMap::new(); for word in text.split(' ') { *counts.entry(word).or_insert(0) += 1; } println!("{} distinct words", counts.len()); assert_eq!(counts["the"],3); assert_eq!(counts["fox"],2); }