[−]Struct libipld_macro::Cid
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 -->", ]);
Representation of a CID.
Methods
impl Cid
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 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>
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
fn clone(&self) -> Cid
fn clone_from(&mut self, source: &Self)
1.0.0[src]
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.
fn from_str(cid_str: &str) -> Result<Cid, Error>
impl Hash for Cid
fn hash<H>(&self, state: &mut H) where
H: Hasher,
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Cid
fn cmp(&self, other: &Cid) -> Ordering
#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Cid> for Cid
impl PartialOrd<Cid> for Cid
fn partial_cmp(&self, other: &Cid) -> Option<Ordering>
fn lt(&self, other: &Cid) -> bool
fn le(&self, other: &Cid) -> bool
fn gt(&self, other: &Cid) -> bool
fn ge(&self, other: &Cid) -> bool
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.
fn try_from(bytes: &[u8]) -> Result<Cid, Error>
impl<'_> TryFrom<&'_ str> for Cid
type Error = Error
The type returned in the event of a conversion error.
fn try_from(cid_str: &str) -> Result<Cid, Error>
impl TryFrom<String> for Cid
type Error = Error
The type returned in the event of a conversion error.
fn try_from(cid_str: String) -> Result<Cid, Error>
impl TryFrom<Vec<u8>> for Cid
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]
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,