Struct libipld::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§
source§impl<const S: usize> Cid<S>
impl<const S: usize> Cid<S>
sourcepub const fn new(
version: Version,
codec: u64,
hash: Multihash<S>,
) -> Result<Cid<S>, Error>
pub const fn new( version: Version, codec: u64, hash: Multihash<S>, ) -> Result<Cid<S>, Error>
Create a new CID.
sourcepub fn into_v1(self) -> Result<Cid<S>, Error>
pub fn into_v1(self) -> Result<Cid<S>, Error>
Convert a CIDv0 to a CIDv1. Returns unchanged if already a CIDv1.
sourcepub fn read_bytes<R>(r: R) -> Result<Cid<S>, Error>where
R: Read,
pub fn read_bytes<R>(r: R) -> Result<Cid<S>, Error>where
R: Read,
Reads the bytes from a byte stream.
sourcepub fn write_bytes<W>(&self, w: W) -> Result<usize, Error>where
W: Write,
pub fn write_bytes<W>(&self, w: W) -> Result<usize, Error>where
W: Write,
Writes the bytes to a byte stream, returns the number of bytes written.
sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Returns the length in bytes needed to encode this cid into bytes.
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 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§
source§impl<'a, const S: usize> Arbitrary<'a> for Cid<S>
impl<'a, const S: usize> Arbitrary<'a> for Cid<S>
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Cid<S>, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Cid<S>, Error>
Self
from the given unstructured data. Read moresource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured
this type
needs to construct itself. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moresource§impl Decode<DagCborCodec> for Cid<64>
impl Decode<DagCborCodec> for Cid<64>
source§impl<'de, const SIZE: usize> Deserialize<'de> for Cid<SIZE>
impl<'de, const SIZE: usize> Deserialize<'de> for Cid<SIZE>
Deserialize a CID into a newtype struct.
Deserialize a CID that was serialized as a newtype struct, so that can be identified as a CID. Its corresponding Rust type would be:
struct $__private__serde__identifier__for__cid(serde_bytes::BytesBuf);
source§fn deserialize<D>(
deserializer: D,
) -> Result<Cid<SIZE>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Cid<SIZE>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl Encode<DagCborCodec> for Cid<64>
impl Encode<DagCborCodec> for Cid<64>
source§impl<const S: usize> Ord for Cid<S>
impl<const S: usize> Ord for Cid<S>
source§impl<const S: usize> PartialEq for Cid<S>
impl<const S: usize> PartialEq for Cid<S>
source§impl<const S: usize> PartialOrd for Cid<S>
impl<const S: usize> PartialOrd for Cid<S>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<const SIZE: usize> Serialize for Cid<SIZE>
impl<const SIZE: usize> Serialize for Cid<SIZE>
Serialize a CID into the Serde data model as enum.
Custom types are not supported by Serde, hence we map a CID into an enum that can be identified as a CID by implementations that support CIDs. The corresponding Rust type would be:
struct $__private__serde__identifier__for__cid(serde_bytes::BytesBuf);
source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)