Content deleted Content added
→Rust: Added looping through only keys |
make Rust example runnable (missing import), reorder iteration examples |
||
Line 1,674:
<syntaxhighlight lang="text">
use std::collections::HashMap;
let mut phone_book = HashMap::new();
phone_book.insert("Sally Smart", "555-9999");
Line 1,680 ⟶ 1,681:
</syntaxhighlight>
The default iterators visit all entries as tuples in an unspecified order:
Loop iterating through all the keys of the hash map:▼
<syntaxhighlight lang="text">
for (name, number) in &phone_book
println!("{} {}", name, number);
}
</syntaxhighlight>
<syntaxhighlight lang="text">
for
println!("
}
</syntaxhighlight>
|