Struct libipld::cid::CidGeneric[]

pub struct CidGeneric<S> where
    S: Size
{ /* fields omitted */ }
Expand description

Representation of a CID.

The generic is about the allocated size of the multihash.

Implementations

impl<S> Cid<S> where
    S: Size

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

Create a new CIDv0.

pub fn new_v1(codec: u64, hash: Multihash<S>) -> Cid<S>

Create a new CIDv1.

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

Create a new CID.

pub fn version(&self) -> Version

Returns the cid version.

pub fn codec(&self) -> u64

Returns the cid codec.

pub fn hash(&self) -> &Multihash<S>

Returns the cid multihash.

pub fn read_bytes<R>(r: R) -> Result<Cid<S>, Error> where
    R: Read

Reads the bytes from a byte stream.

pub fn write_bytes<W>(&self, w: W) -> Result<(), Error> where
    W: Write

Writes the bytes to a byte stream.

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

Returns the encoded bytes of the Cid.

pub fn to_string_of_base(&self, base: Base) -> Result<String, Error>

Convert CID into a multibase encoded string

Example

use cid::Cid;
use multibase::Base;
use multihash::{Code, MultihashDigest};

const RAW: u64 = 0x55;

let cid = Cid::new_v1(RAW, Code::Sha2_256.digest(b"foo"));
let encoded = cid.to_string_of_base(Base::Base64).unwrap();
assert_eq!(encoded, "mAVUSICwmtGto/8aP+ZtFPB0wQTQTQi1wZIO/oPmKXohiZueu");

Trait Implementations

impl<T> AsRef<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Link<T>[src]

pub fn as_ref(
    &self
) -> &Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
[src]

Performs the conversion.

impl<S> AsRef<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]

fn as_ref(&self) -> &Cid[src]

Performs the conversion.

impl<S> Borrow<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Block<S>[src]

fn borrow(&self) -> &Cid[src]

Immutably borrows from an owned value. Read more

impl<S> Clone for Cid<S> where
    S: Clone + Size

pub fn clone(&self) -> Cid<S>

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<S> Debug for Cid<S> where
    S: Size

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

impl Decode<DagCborCodec> for Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>[src]

pub fn decode<R>(
    DagCborCodec,
    r: &mut R
) -> Result<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>, Error> where
    R: Read + Seek
[src]

Decode from an impl Read. Read more

impl<S> Default for Cid<S> where
    S: Size

pub fn default() -> Cid<S>

Returns the “default value” for a type. Read more

impl<S> Display for Cid<S> where
    S: Size

pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

impl Encode<DagCborCodec> for Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>[src]

pub fn encode<W>(&self, DagCborCodec, w: &mut W) -> Result<(), Error> where
    W: Write
[src]

Encodes into a impl Write. Read more

impl<'_, S> From<&'_ Cid<S>> for Cid<S> where
    S: Size,
    <S as ArrayLength<u8>>::ArrayType: Copy

pub fn from(cid: &Cid<S>) -> Cid<S>

Performs the conversion.

impl<'_> From<&'_ Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Ipld[src]

pub fn from(
    t: &Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
) -> Ipld
[src]

Performs the conversion.

impl<'a> From<&'a Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for DagPath<'a>[src]

fn from(cid: &'a Cid) -> Self[src]

Performs the conversion.

impl From<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Ipld[src]

pub fn from(
    t: Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
) -> Ipld
[src]

Performs the conversion.

impl<T> From<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>> for Link<T>[src]

pub fn from(
    cid: Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>
) -> Link<T>
[src]

Performs the conversion.

impl<S> FromStr for Cid<S> where
    S: Size

type Err = Error

The associated error which can be returned from parsing.

pub fn from_str(cid_str: &str) -> Result<Cid<S>, Error>

Parses a string s to return a value of this type. Read more

impl<S> Hash for Cid<S> where
    S: Hash + Size

pub fn hash<__H>(&self, state: &mut __H) where
    __H: Hasher

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

impl<S> Ord for Cid<S> where
    S: Ord + Size

pub fn cmp(&self, other: &Cid<S>) -> Ordering

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<S> PartialEq<Cid<S>> for Cid<S> where
    S: PartialEq<S> + Size

pub fn eq(&self, other: &Cid<S>) -> bool

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

pub fn ne(&self, other: &Cid<S>) -> bool

This method tests for !=.

impl<S> PartialOrd<Cid<S>> for Cid<S> where
    S: PartialOrd<S> + Size

pub fn partial_cmp(&self, other: &Cid<S>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'_, S> TryFrom<&'_ [u8]> for Cid<S> where
    S: Size

type Error = Error

The type returned in the event of a conversion error.

pub fn try_from(bytes: &[u8]) -> Result<Cid<S>, Error>

Performs the conversion.

impl<'_, S> TryFrom<&'_ str> for Cid<S> where
    S: Size

type Error = Error

The type returned in the event of a conversion error.

pub fn try_from(cid_str: &str) -> Result<Cid<S>, Error>

Performs the conversion.

impl<S> TryFrom<String> for Cid<S> where
    S: Size

type Error = Error

The type returned in the event of a conversion error.

pub fn try_from(cid_str: String) -> Result<Cid<S>, Error>

Performs the conversion.

impl<S> TryFrom<Vec<u8, Global>> for Cid<S> where
    S: Size

type Error = Error

The type returned in the event of a conversion error.

pub fn try_from(bytes: Vec<u8, Global>) -> Result<Cid<S>, Error>

Performs the conversion.

impl<S> Copy for Cid<S> where
    S: Size,
    <S as ArrayLength<u8>>::ArrayType: Copy

impl<S> Eq for Cid<S> where
    S: Eq + Size

impl<S> StructuralEq for Cid<S> where
    S: Size

impl<S> StructuralPartialEq for Cid<S> where
    S: Size

Auto Trait Implementations

impl<S> RefUnwindSafe for Cid<S> where
    <S as ArrayLength<u8>>::ArrayType: RefUnwindSafe

impl<S> Send for Cid<S>

impl<S> Sync for Cid<S>

impl<S> Unpin for Cid<S> where
    <S as ArrayLength<u8>>::ArrayType: Unpin

impl<S> UnwindSafe for Cid<S> where
    <S as ArrayLength<u8>>::ArrayType: UnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> References<RawCodec> for T[src]

pub fn references<R, E>(
    _c: RawCodec,
    _r: &mut R,
    _set: &mut E
) -> Result<(), Error> where
    E: Extend<Cid<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>>>,
    R: Read
[src]

Scrape the references from an impl Read. Read more

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.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

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

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> DagCbor for T where
    T: Encode<DagCborCodec> + Decode<DagCborCodec>, 
[src]