[−][src]Enum libipld_macro::Ipld
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
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.
Represents a sequence of bytes.
Represents a list.
Represents a map.
Represents a link to an Ipld node.
Implementations
impl Ipld
[src]
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 -->", ]);
pub fn get<'a, T>(&self, index: T) -> Result<&Ipld, TypeError> where
T: Into<IpldIndex<'a>>,
[src]
T: Into<IpldIndex<'a>>,
Indexes into a ipld list or map.
pub fn iter(&self) -> IpldIter<'_>
[src]
Returns an iterator.
pub fn references(&self) -> HashSet<Cid, RandomState>
[src]
Returns the references to other blocks.
Trait Implementations
impl Clone for Ipld
[src]
impl Debug for Ipld
[src]
impl Decode<RawCodec> for Ipld
[src]
impl Encode<RawCodec> for Ipld
[src]
impl<'_> From<&'_ [u8]> for Ipld
[src]
impl<'_> From<&'_ Cid> for Ipld
[src]
impl<'_> From<&'_ str> for Ipld
[src]
impl From<BTreeMap<String, Ipld>> for Ipld
[src]
impl From<Box<[u8]>> for Ipld
[src]
impl From<Cid> for Ipld
[src]
impl From<String> for Ipld
[src]
impl From<Vec<Ipld>> for Ipld
[src]
impl From<Vec<u8>> for Ipld
[src]
impl From<bool> for Ipld
[src]
impl From<f32> for Ipld
[src]
impl From<f64> for Ipld
[src]
impl From<i128> for Ipld
[src]
impl From<i16> for Ipld
[src]
impl From<i32> for Ipld
[src]
impl From<i64> for Ipld
[src]
impl From<i8> for Ipld
[src]
impl From<isize> for Ipld
[src]
impl From<u16> for Ipld
[src]
impl From<u32> for Ipld
[src]
impl From<u64> for Ipld
[src]
impl From<u8> for Ipld
[src]
impl From<usize> for Ipld
[src]
impl PartialEq<Ipld> for Ipld
[src]
impl StructuralPartialEq for Ipld
[src]
Auto Trait Implementations
impl RefUnwindSafe for Ipld
impl Send for Ipld
impl Sync for Ipld
impl Unpin for Ipld
impl UnwindSafe for Ipld
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,