Map<K, V>
Map is an ordered key-value dictionary. The map is ordered by its keys. Iterating a map is stable and always returns the keys and values in order of the keys. The map is stored in the Host and available to the Guest through the functions defined on Map. Values stored in the Map are transmitted to the Host asVals, and when retrieved from the Map are transmitted back and converted from Val back into their type.
Type Safety
The pairs of keys and values in a Map are not guaranteed to be of typeK/V and conversion will fail if they are not. Most functions on Map return a Result due to this.
Maps have at most one entry per key. Setting a value for a key in the map that already has a value for that key replaces the value.
Constructor Methods
new
from_array
Key Operations
contains_key
get
try_get
get_unchecked
- If the map does not contain a value with the specified key.
- If the value corresponding to the key cannot be converted to type V.
try_get_unchecked
Modification Methods
set
remove
None if the map does not contain a value with the specified key.
remove_unchecked
Collection Methods
keys
values
Utility Methods
is_empty
len
Iterator Methods
iter
try_iter
into_try_iter
Conversion Methods
env
as_val
to_val
Macro
map!
(key, value).
Example:
Usage Examples
Basic Usage
Maps Are Ordered
Maps created with elements in different order will be equal because they are ordered by keys.Iterating Over a Map
Checking for Keys
Getting and Setting Values
Removing Values
Getting Keys and Values
See Also
Vecfor sequential collectionsStoragefor persistent storage