Struct cid::CidGeneric[][src]

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

Representation of a CID.

The generic is about the allocated size of the multihash.

Implementations

impl<S: Size> Cid<S>[src]

pub fn new_v0(hash: Multihash<S>) -> Result<Self>[src]

Create a new CIDv0.

pub fn new_v1(codec: u64, hash: Multihash<S>) -> Self[src]

Create a new CIDv1.

pub fn new(version: Version, codec: u64, hash: Multihash<S>) -> Result<Self>[src]

Create a new CID.

pub fn version(&self) -> Version[src]

Returns the cid version.

pub fn codec(&self) -> u64[src]

Returns the cid codec.

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

Returns the cid multihash.

pub fn read_bytes<R: Read>(r: R) -> Result<Self>[src]

Reads the bytes from a byte stream.

pub fn write_bytes<W: Write>(&self, w: W) -> Result<()>[src]

Writes the bytes to a byte stream.

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

Returns the encoded bytes of the Cid.

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

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<S: Clone + Size> Clone for Cid<S>[src]

impl<S: Size> Copy for Cid<S> where
    S::ArrayType: Copy
[src]

impl<S: Size> Debug for Cid<S>[src]

impl<S: Size> Default for Cid<S>[src]

impl<S: Size> Display for Cid<S>[src]

impl<S: Eq + Size> Eq for Cid<S>[src]

impl<S: Size> From<&'_ Cid<S>> for Cid<S> where
    S::ArrayType: Copy
[src]

impl<S: Size> FromStr for Cid<S>[src]

type Err = Error

The associated error which can be returned from parsing.

impl<S: Hash + Size> Hash for Cid<S>[src]

impl<S: Ord + Size> Ord for Cid<S>[src]

impl<S: PartialEq + Size> PartialEq<Cid<S>> for Cid<S>[src]

impl<S: PartialOrd + Size> PartialOrd<Cid<S>> for Cid<S>[src]

impl<S: Size> StructuralEq for Cid<S>[src]

impl<S: Size> StructuralPartialEq for Cid<S>[src]

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

type Error = Error

The type returned in the event of a conversion error.

impl<S: Size> TryFrom<&'_ str> for Cid<S>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<S: Size> TryFrom<String> for Cid<S>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<S: Size> TryFrom<Vec<u8, Global>> for Cid<S>[src]

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
[src]

impl<S> Send for Cid<S>[src]

impl<S> Sync for Cid<S>[src]

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

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

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,