Enum libipld_macro::Ipld
source · pub enum Ipld {
Null,
Bool(bool),
Integer(i128),
Float(f64),
String(String),
Bytes(Vec<u8, Global>),
List(Vec<Ipld, Global>),
Map(BTreeMap<String, Ipld, Global>),
Link(Cid<64>),
}
Expand description
Construct an Ipld
from a literal.
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.
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.
let value = ipld!([
"notice",
"the",
"trailing",
"comma -->",
]);
Ipld
Variants§
Null
Represents the absence of a value or the value undefined.
Bool(bool)
Represents a boolean value.
Integer(i128)
Represents an integer.
Float(f64)
Represents a floating point value.
String(String)
Represents an UTF-8 string.
Bytes(Vec<u8, Global>)
Represents a sequence of bytes.
List(Vec<Ipld, Global>)
Represents a list.
Map(BTreeMap<String, Ipld, Global>)
Represents a map of strings.
Link(Cid<64>)
Represents a map of integers.
Implementations§
source§impl Ipld
impl Ipld
sourcepub fn take<'a, T>(self, index: T) -> Result<Ipld, TypeError>where
T: Into<IpldIndex<'a>>,
pub fn take<'a, T>(self, index: T) -> Result<Ipld, TypeError>where
T: Into<IpldIndex<'a>>,
Destructs an ipld list or map
sourcepub fn get<'a, T>(&self, index: T) -> Result<&Ipld, TypeError>where
T: Into<IpldIndex<'a>>,
pub fn get<'a, T>(&self, index: T) -> Result<&Ipld, TypeError>where
T: Into<IpldIndex<'a>>,
Indexes into an ipld list or map.
sourcepub fn references<E>(&self, set: &mut E)where
E: Extend<Cid<64>>,
pub fn references<E>(&self, set: &mut E)where
E: Extend<Cid<64>>,
Returns the references to other blocks.