[−]Type Definition libipld_macro::Cid
type Cid = CidGeneric<Codec, Code>;
Construct an Ipld
from a literal.
ⓘThis code runs with edition 2018
let value = ipld!({ "code": 200, "success": true, "payload": { "features": [ "serde", "json" ] } });
Variables or expressions can be interpolated into the JSON 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 json!
macro will panic.
ⓘThis code runs with edition 2018
let code = 200; let features = vec!["serde", "json"]; let value = ipld!({ "code": code, "success": code == 200, "payload": { features[0]: features[1] } });
Trailing commas are allowed inside both arrays and objects.
ⓘThis code runs with edition 2018
let value = ipld!([ "notice", "the", "trailing", "comma -->", ]);
A CID with the default Multihash code table