mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-12 02:18:08 +08:00
17 lines
321 B
Rust
17 lines
321 B
Rust
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
|
|
}
|