trpl-zh-cn/listings/ch08-common-collections/listing-08-25/src/main.rs
2023-01-16 17:34:52 +08:00

17 lines
323 B
Rust
Executable File

fn main() {
// ANCHOR: here
use std::collections::HashMap;
let text = "hello world wonderful world";
let mut map = HashMap::new();
for word in text.split_whitespace() {
let count = map.entry(word).or_insert(0);
*count += 1;
}
println!("{:?}", map);
// ANCHOR_END: here
}