pub struct Cid { /* private fields */ }Expand description
A CIDv1 content identifier.
Internally stored as a fixed-size byte buffer holding the full CID bytes
(0x01 <codec> <multihash>), plus a length. CIDv1 with a single-byte codec
varint and SHA-256 multihash is exactly 38 bytes, so a 40-byte inline buffer
covers all realistic multihashes without a heap allocation. This makes
Cid Copy (38-ish bytes is cheaper to copy than to refcount), which
matters because CIDs flow through tree node fields, map keys, and proof
steps that would otherwise drown in .clone() noise.
Implementations§
Source§impl Cid
impl Cid
Sourcepub fn from_dag_cbor(block_bytes: &[u8]) -> Self
pub fn from_dag_cbor(block_bytes: &[u8]) -> Self
Compute the CIDv1 dag-cbor CID over block_bytes (SHA-256 multihash).
This is the canonical way to address a DAG-CBOR block in atproto: the
caller hands in the already-canonical DAG-CBOR bytes (see crate::dag_cbor)
and gets back the CID that identifies them.
Sourcepub fn from_raw(blob_bytes: &[u8]) -> Self
pub fn from_raw(blob_bytes: &[u8]) -> Self
CIDv1 raw codec over arbitrary bytes (used for external git OIDs
referenced by currentOid when the caller has the raw blob handy).
Sourcepub fn to_link_bytes(&self) -> Vec<u8> ⓘ
pub fn to_link_bytes(&self) -> Vec<u8> ⓘ
Encode as a DAG-CBOR link: the CBOR-tag-42 payload, i.e. a leading
0x00 identity-multibase marker followed by the raw CID bytes.
Returns the bytes that go inside the tag-42 byte string (the marker
plus the CID). Used by crate::dag_cbor when emitting link values.
Sourcepub fn from_link_bytes(link: &[u8]) -> Result<Self>
pub fn from_link_bytes(link: &[u8]) -> Result<Self>
Parse a DAG-CBOR tag-42 payload (leading 0x00 marker + CID) back into a Cid.
Sourcepub fn from_bytes(raw: &[u8]) -> Result<Self>
pub fn from_bytes(raw: &[u8]) -> Result<Self>
Parse raw CID bytes (version + codec + multihash).
Sourcepub fn encode(&self) -> String
pub fn encode(&self) -> String
Base32 (lowercase, no padding) bafy.../bafk...-style encoding — the
canonical string form of a CIDv1.
Named encode rather than to_string to avoid shadowing the
ToString blanket impl that Display would otherwise recurse through.
This is the CIDv1 string format:
multibase prefix b (base32lower-nopad) followed by the base32 of the
raw CID bytes.
Trait Implementations§
Source§impl Ord for Cid
impl Ord for Cid
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Cid
impl PartialOrd 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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more