Struct cid::CidGeneric
source · [−]pub struct CidGeneric<const S: usize> { /* private fields */ }
Expand description
Representation of a CID.
The generic is about the allocated size of the multihash.
Implementations
sourceimpl<const S: usize> Cid<S>
impl<const S: usize> Cid<S>
sourcepub const fn new(version: Version, codec: u64, hash: Multihash<S>) -> Result<Self>
pub const fn new(version: Version, codec: u64, hash: Multihash<S>) -> Result<Self>
Create a new CID.
sourcepub fn into_v1(self) -> Result<Self>
pub fn into_v1(self) -> Result<Self>
Convert a CIDv0 to a CIDv1. Returns unchanged if already a CIDv1.
sourcepub fn read_bytes<R: Read>(r: R) -> Result<Self>
pub fn read_bytes<R: Read>(r: R) -> Result<Self>
Reads the bytes from a byte stream.
sourcepub fn write_bytes<W: Write>(&self, w: W) -> Result<()>
pub fn write_bytes<W: Write>(&self, w: W) -> Result<()>
Writes the bytes to a byte stream.
sourcepub fn to_string_of_base(&self, base: Base) -> Result<String>
pub fn to_string_of_base(&self, base: Base) -> Result<String>
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
sourceimpl<const S: usize> Ord for Cid<S>
impl<const S: usize> Ord for Cid<S>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<const S: usize> PartialOrd<Cid<S>> for Cid<S>
impl<const S: usize> PartialOrd<Cid<S>> for Cid<S>
sourcefn partial_cmp(&self, other: &Cid<S>) -> Option<Ordering>
fn partial_cmp(&self, other: &Cid<S>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<const S: usize> Copy for Cid<S>
impl<const S: usize> Eq for Cid<S>
impl<const S: usize> StructuralEq for Cid<S>
impl<const S: usize> StructuralPartialEq for Cid<S>
Auto Trait Implementations
impl<const S: usize> RefUnwindSafe for Cid<S>
impl<const S: usize> Send for Cid<S>
impl<const S: usize> Sync for Cid<S>
impl<const S: usize> Unpin for Cid<S>
impl<const S: usize> UnwindSafe for Cid<S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more