Logo

Programming-Idioms

History of Idiom 112 > diff from v17 to v18

Edit summary for version 18 by programming-idioms.org:
[Rust] Comments emphasis

Version 17

2018-06-12, 19:01:23

Version 18

2018-08-03, 21:23:49

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
for (k, x) in mymap {
    println!("({}, {})", k, x);
}
Code
for (k, x) in mymap {
    println!("({}, {})", k, x);
}
Comments bubble
This assumes mymap is a BTreeMap as it is sorted by the keys.
Comments bubble
This assumes mymap is a BTreeMap as it is sorted by the keys.
Doc URL
https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html#method.iter
Doc URL
https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html#method.iter