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_v1(codec: u64, hash: RawMultihash) -> Cid
pub fn new_v1(codec: u64, hash: RawMultihash) -> Cid
Create a new CIDv1.
Sourcepub fn new(
version: Version,
codec: u64,
hash: RawMultihash,
) -> Result<Cid, Error>
pub fn new( version: Version, codec: u64, hash: RawMultihash, ) -> Result<Cid, Error>
Create a new CID.
Sourcepub fn hash(&self) -> &RawMultihash
pub fn hash(&self) -> &RawMultihash
Returns the cid multihash.
Sourcepub fn read_bytes<R>(r: R) -> Result<Cid, Error>where
R: Read,
pub fn read_bytes<R>(r: R) -> Result<Cid, Error>where
R: Read,
Reads the bytes from a byte stream.
Sourcepub fn write_bytes<W>(&self, w: W) -> Result<(), Error>where
W: Write,
pub fn write_bytes<W>(&self, w: W) -> Result<(), Error>where
W: Write,
Writes the bytes to a byte stream.
Sourcepub fn to_string_of_base(&self, base: Base) -> Result<String, Error>
pub fn to_string_of_base(&self, base: Base) -> Result<String, Error>
Convert CID into a multibase encoded string
§Example
use tiny_cid::{RAW, Cid};
use multibase::Base;
use tiny_multihash::{SHA2_256, Multihash, MultihashDigest};
let mh = Multihash::new(SHA2_256, b"foo").unwrap();
let cid = Cid::new_v1(RAW, mh.to_raw().unwrap());
let encoded = cid.to_string_of_base(Base::Base64).unwrap();
assert_eq!(encoded, "mAVUSICwmtGto/8aP+ZtFPB0wQTQTQi1wZIO/oPmKXohiZueu");Trait Implementations§
Source§impl Decode<DagCborCodec> for Cid
impl Decode<DagCborCodec> for Cid
Source§impl Encode<DagCborCodec> for Cid
impl Encode<DagCborCodec> for Cid
Source§impl TryReadCbor for Cid
impl TryReadCbor for Cid
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