macro_rules! encom_from_json {
($($encom_from_json:tt)+) => { ... };
}Expand description
Construct a serde_encom::Value from an EnCom literal.
let value = encom_from_json!({
"code": 200,
"success": true,
"payload": {
"features": [
"serde",
"encom"
]
}
});Variables or expressions can be interpolated into the EnCom literal. Any type
interpolated into an array element or object value must implement Serde’s
Serialize trait, while any type interpolated into a object key must
implement Into<String>. If the Serialize implementation of the
interpolated type decides to fail, or if the interpolated type contains a
map with non-string keys, the encom_from_json! macro will panic.
let code = 200;
let features = vec!["serde", "encom"];
let value = encom_from_json!({
"code": code,
"success": code == 200,
"payload": {
features[0]: features[1]
}
});Trailing commas are allowed inside both arrays and objects.
let value = encom_from_json!([
"notice",
"the",
"trailing",
"comma -->",
]);