macro_rules! value { ( $($tt:tt)+ ) => { ... }; () => { ... }; }
Available on crate feature
serde
only.Expand description
Convenient macro for constructing a Value
.
The macro always returns a Value::Map
variant at the
top level but the map values can be any variant. The keys must be
identifiers not string literals, similar to Rust’s struct initialization
syntax.
§Examples
let v = upon::value!{
users: [
{
name: "John Smith",
age: 36,
is_enabled: true,
address: None,
},
{
name: "Jane Doe",
age: 34,
is_enabled: false,
},
]
};
Variables and expressions can be interpolated as map values,
to_value
will be used to convert the expression to a
Value
.
let names = vec!["John", "James"];
let addr = "42 Wallaby Way, Sydney";
let v = upon::value!{
names: names,
surname: "Smith",
address: addr,
};