pub struct Cid { /* private fields */ }
Expand description
Representation of a CID.
Usually you would use Cid
instead, unless you have a custom Multihash code table
Implementations§
Source§impl Cid
impl Cid
Sourcepub fn new(version: Version, codec: u64, hash: Multihash<U64>) -> Result<Self>
pub fn new(version: Version, codec: u64, hash: Multihash<U64>) -> Result<Self>
Create a new CID.
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 tiny_cid::{RAW, Cid};
use multibase::Base;
use tiny_multihash::{Code, MultihashCode};
let mh = Code::Sha2_256.digest(b"foo");
let cid = Cid::new_v1(RAW, mh);
let encoded = cid.to_string_of_base(Base::Base64).unwrap();
assert_eq!(encoded, "mAVUSICwmtGto/8aP+ZtFPB0wQTQTQi1wZIO/oPmKXohiZueu");
Trait Implementations§
impl Copy for Cid
impl Eq for Cid
impl StructuralPartialEq for Cid
Auto Trait Implementations§
impl Freeze for Cid
impl RefUnwindSafe for Cid
impl Send for Cid
impl Sync for Cid
impl Unpin for Cid
impl UnwindSafe for Cid
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