Macro dict
macro_rules! dict {
($($key:tt: $value:expr),* $(,)?) => { ... };
}Expand description
Constructs typed Dictionary<K, V> literals, close to Godot’s own syntax.
Any value can be used as a key, but to use an expression you need to surround it
in () or {}.
§Type annotation
The macro creates a typed Dictionary<K, V>. You must provide an explicit type annotation
to specify K and V. Keys must implement AsArg<K> and values must implement AsArg<V>.
§Example
use godot::builtin::{dict, Dictionary, GString, Variant};
// Type annotation required
let d: Dictionary<GString, i64> = dict! {
"key1": 10,
"key2": 20,
};
// Works with Variant values too
let d: Dictionary<GString, Variant> = dict! {
"str": "Hello",
"num": 23,
};§See also
For untyped dictionaries, use vdict!.
For arrays, similar macros array! and varray! exist.