[]Struct libipld_macro::Cid

pub struct Cid { /* fields omitted */ }

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

Representation of a CID.

Methods

impl Cid

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

pub fn new_v0(hash: Multihash) -> Result<Cid, Error>

Create a new CIDv0.

pub fn new_v1(codec: Codec, hash: Multihash) -> Cid

Create a new CIDv1.

pub fn new(
    version: Version,
    codec: Codec,
    hash: Multihash
) -> Result<Cid, Error>

Create a new CID.

pub fn new_from_prefix(prefix: &Prefix, data: &[u8]) -> Cid

Create a new CID from a prefix and some data.

pub fn version(&self) -> Version

Returns the cid version.

pub fn codec(&self) -> Codec

Returns the cid codec.

pub fn hash(&self) -> MultihashRef

Returns the cid multihash.

pub fn to_bytes(&self) -> Vec<u8>

Convert CID to encoded bytes.

pub fn prefix(&self) -> Prefix

Return the prefix of the CID.

Trait Implementations

impl Clone for Cid

impl Debug for Cid

impl Display for Cid

impl Eq for Cid

impl<'_> From<&'_ Cid> for Ipld[src]

impl<'_> From<&'_ Cid> for Cid

impl From<Cid> for Ipld[src]

impl FromStr for Cid

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Cid

impl Ord for Cid

impl PartialEq<Cid> for Cid

impl PartialOrd<Cid> for Cid

impl StructuralEq for Cid

impl StructuralPartialEq for Cid

impl<'_> TryFrom<&'_ [u8]> for Cid

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ str> for Cid

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<String> for Cid

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<Vec<u8>> for Cid

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Cid

impl Send for Cid

impl Sync for Cid

impl Unpin for Cid

impl UnwindSafe for Cid

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.