Dictionaries
{K: V} maps keys to values. Keys may be integers, strings, booleans, payload-free enums, or tuples made from those types. {:} is the empty dictionary.
A bare loop binding receives keys. A top-level tuple pattern receives (key, value) entries. Dictionaries preserve first-insertion order, including when a value is replaced.
fn main() {
let mut ages = {"Ada": 36, "Grace": 36}
ages["Ada"] += 1
for (name, age) in ages {
println("$name:$age")
}
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: Ada:37 Grace:36
Ctrl/⌘+Enter runs the current lesson.