macro_rules! context { () => { ... }; ( $($key:ident $(=> $value:expr)?),* $(,)? ) => { ... }; }
Expand description
Creates a template context with keys and values.
let ctx = context! {
name => "Peter",
location => "World",
};
Alternatively if the variable name matches the key name it can be omitted:
let name = "Peter";
let ctx = context! { name };
The return value is a Value
.
Note that context!
can also be used recursively if you need to
create nested objects:
let ctx = context! {
nav => vec![
context!(path => "/", title => "Index"),
context!(path => "/downloads", title => "Downloads"),
context!(path => "/faq", title => "FAQ"),
]
};