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§
Source§impl<const S: usize> Cid<S>
impl<const S: usize> Cid<S>
Sourcepub fn new(version: Version, codec: Codec, hash: Multihash<S>) -> Result<Self>
pub fn new(version: Version, codec: Codec, hash: Multihash<S>) -> Result<Self>
Create a new CID.
Sourcepub fn read_bytes(r: &mut ByteCursor) -> Result<Self>
pub fn read_bytes(r: &mut ByteCursor) -> Result<Self>
Reads the bytes from a byte stream.
Sourcepub fn write_bytes(&self, w: &mut ByteCursor) -> Result<()>
pub fn write_bytes(&self, w: &mut ByteCursor) -> 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 multibase::Base;
use sp_cid::{
codec,
Cid,
};
use sp_multihash::{
Code,
MultihashDigest,
};
let cid = Cid::new_v1(codec::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§
Source§impl<const S: usize> Ord for Cid<S>
impl<const S: usize> Ord for Cid<S>
Source§impl<const S: usize> PartialOrd for Cid<S>
impl<const S: usize> PartialOrd for Cid<S>
impl<const S: usize> Copy for Cid<S>
impl<const S: usize> Eq for Cid<S>
impl<const S: usize> StructuralPartialEq for Cid<S>
Auto Trait Implementations§
impl<const S: usize> Freeze for Cid<S>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more