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<Self>
pub const fn new( version: Version, codec: u64, hash: Multihash<S>, ) -> Result<Self>
Create a new CID.
Sourcepub fn into_v1(self) -> Result<Self>
pub fn into_v1(self) -> Result<Self>
Convert a CIDv0 to a CIDv1. Returns unchanged if already a CIDv1.
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<usize>
pub fn write_bytes<W: Write>(&self, w: W) -> Result<usize>
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>
pub fn to_string_of_base(&self, base: Base) -> Result<String>
Convert CID into a multibase encoded string
§Example
use {
cid::Cid,
multibase::Base,
multihash_codetable::{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<const S: usize> Decode for Cid<S>
impl<const S: usize> Decode for Cid<S>
Source§fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> Result<Self, Error>
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Source§impl<'de, const SIZE: usize> Deserialize<'de> for CidGeneric<SIZE>
Deserialize a CID into a newtype struct.
impl<'de, const SIZE: usize> Deserialize<'de> for CidGeneric<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<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const S: usize> Encode for Cid<S>
impl<const S: usize> Encode for Cid<S>
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
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>
Source§impl<const SIZE: usize> Serialize for CidGeneric<SIZE>
Serialize a CID into the Serde data model as enum.
impl<const SIZE: usize> Serialize for CidGeneric<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);