macro_rules! dict {
{ $($key:tt => $value:expr),* $(,)? } => { ... };
}Expand description
A macro for creating a Dict from literals
Keys can be bare identifiers or string/expression literals.
Bare identifiers are stringified, so site => ... becomes the key "site".
If you want to use a const or other expression as the key, wrap it in
parentheses, such as (KEY_SITE) => ....
Values can be any type that implements Into<Value> (e.g. bool, f64,
i32, &str, haystack types, or explicit Value::... expressions).
ยงExample
use libhaystack::*;
use libhaystack::val::*;
// String keys with explicit Value expressions (original syntax)
let dict = dict!{
"site" => Value::make_marker(),
"dis" => Value::make_str("Some site")
};
// Identifier keys with native/std types
let dict2 = dict!{
site => Marker,
dis => "Some site"
};
// Const/expression keys must be parenthesized
const KEY_SITE: &str = "site";
let dict3 = dict!{
(KEY_SITE) => Marker,
};