Struct libipld::cid::CidGeneric[]

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

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]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

type Err = Error

The associated error which can be returned from parsing.

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

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

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

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

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

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

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

type Error = Error

The type returned in the event of a conversion error.

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

type Error = Error

The type returned in the event of a conversion error.

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

type Error = Error

The type returned in the event of a conversion error.

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.

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]

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

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

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

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

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

impl<T> References<RawCodec> for 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.