Here is a piece of code that counts the frequency of words in a sentence.
I'm wondering if the HashMap
can be set as immutable after counting the items.
let mut map = HashMap::new();
for word in s.split_whitespace() {
*map.entry(word).or_insert(0) += 1;
}
// after the for loop make map immutable
I'm aware of the crate Counter
with the collect
API but I'd prefer to do it without crates.
I would also prefer a solution that doesn't use functions or closures.