pub enum Ipld {
    Null,
    Bool(bool),
    Integer(i128),
    Float(f64),
    String(String),
    Bytes(Vec<u8, Global>),
    List(Vec<Ipld, Global>),
    Map(BTreeMap<String, Ipld>),
    Link(Cid<64_usize>),
}
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>)

Represents a map of strings.

Represents a map of integers.

Implementations

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 -->",
]);

Destructs an ipld list or map

Indexes into an ipld list or map.

Returns an iterator.

Returns the references to other blocks.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Decode from an impl Read. Read more

Encodes into a impl Write. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Scrape the references from an impl Read. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.