[−]Struct libipld::Cid
Representation of a CID.
Usually you would use Cid
instead, unless you have a custom Multihash code table
Implementations
impl Cid
pub fn new_v0(hash: RawMultihash) -> Result<Cid, Error>
Create a new CIDv0.
pub fn new_v1(codec: u64, hash: RawMultihash) -> Cid
Create a new CIDv1.
pub fn new(
version: Version,
codec: u64,
hash: RawMultihash
) -> Result<Cid, Error>
version: Version,
codec: u64,
hash: RawMultihash
) -> Result<Cid, Error>
Create a new CID.
pub fn version(&self) -> Version
Returns the cid version.
pub fn codec(&self) -> u64
Returns the cid codec.
pub fn hash(&self) -> &RawMultihash
Returns the cid multihash.
pub fn read_bytes<R>(r: R) -> Result<Cid, Error> where
R: Read,
R: Read,
Reads the bytes from a byte stream.
pub fn write_bytes<W>(&self, w: W) -> Result<(), Error> where
W: Write,
W: Write,
Writes the bytes to a byte stream.
pub fn to_bytes(&self) -> Vec<u8>
Returns the encoded bytes of the Cid
.
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
impl<S> AsRef<Cid> for Block<S>
[src]
impl<S> Borrow<Cid> for Block<S>
[src]
impl<S: StoreParams> Borrow<Cid> for BlockInfo<S>
[src]
impl Clone for Cid
fn clone(&self) -> Cid
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Cid
impl Decode<DagCborCodec> for Cid
[src]
impl Default for Cid
impl Display for Cid
impl Encode<DagCborCodec> for Cid
[src]
impl Eq for Cid
impl<'_> From<&'_ Cid> for Ipld
[src]
impl<'_> From<&'_ Cid> for Cid
impl<'a> From<&'a Cid> for DagPath<'a>
[src]
impl From<Cid> for Ipld
[src]
impl FromStr for Cid
type Err = Error
The associated error which can be returned from parsing.
fn from_str(cid_str: &str) -> Result<Cid, Error>
impl Hash for Cid
fn hash<T>(&self, state: &mut T) where
T: Hasher,
T: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Cid> for Cid
impl<'_> TryFrom<&'_ [u8]> for Cid
type Error = Error
The type returned in the event of a conversion error.
fn try_from(bytes: &[u8]) -> Result<Cid, Error>
impl<'_> TryFrom<&'_ str> for Cid
type Error = Error
The type returned in the event of a conversion error.
fn try_from(cid_str: &str) -> Result<Cid, Error>
impl TryFrom<String> for Cid
type Error = Error
The type returned in the event of a conversion error.
fn try_from(cid_str: String) -> Result<Cid, Error>
impl TryFrom<Vec<u8>> for Cid
type Error = Error
The type returned in the event of a conversion error.
fn try_from(bytes: Vec<u8>) -> Result<Cid, Error>
impl TryReadCbor for Cid
[src]
Auto Trait Implementations
impl RefUnwindSafe for Cid
impl Send for Cid
impl Sync for Cid
impl Unpin for Cid
impl UnwindSafe for Cid
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DagCbor for T where
T: TryReadCbor + Encode<DagCborCodec> + Decode<DagCborCodec>,
[src]
T: TryReadCbor + Encode<DagCborCodec> + Decode<DagCborCodec>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,