> built-in type
map
methods of map values
Maps in xur are shared and change in place, like lists. These are methods on any map value (#{}); there is no module to import. The type is written map in annotations (e.g. a struct field or parameter); like a list, only the container is type-checked — keys and values are dynamic.
In the signatures, K is the type of the map's keys and V the type of its values.
Keys must be integers, strings, booleans, () or enum variants without fields. Using another value as a key, such as a float or a list, is a runtime error.
A map has no order: keys, values and entries list the entries in an arbitrary order that can change as the map changes.
> methods
map.clear()Removes every entry.
map.contains_key(key: K) -> boolWhether the map has an entry for key.
map.get(key: K) -> Option<V>The value stored under key, or None if there is none.
map.insert(key: K, value: V)Stores value under key, replacing any value already there.
map.is_empty() -> boolWhether the map has no entries.
map.remove(key: K) -> Option<V>Removes the entry for key and returns its value, or None if there was none.
> examples
use std::io;
fn main() {
let m = #{"a": 1, "b": 2};
m.insert("c", 3);
io::println("len: {}", m.len());
match m.get("a") {
Some(v) => io::println("a = {}", v),
None => io::println("not found"),
}
for entry in m.entries() {
io::println("{} -> {}", entry.0, entry.1);
}
}