pub enum ClassifiedCid {
Content(ContentId),
Raw(RawContentId),
Foreign(ForeignCid),
}Expand description
A CID classified by profile. See the module docs for the canonical form invariant.
Variants§
Content(ContentId)
This crate’s dag-cbor profile: the identity of a canonical structured value. Mintable.
Raw(RawContentId)
This crate’s raw profile: the identity of an opaque byte string. Mintable.
Foreign(ForeignCid)
A well-formed CID of any other profile (another codec, another hash such
as sha2-256 0x12, another digest length, or CIDv0), validated by
ForeignCid so it can never alias a recognized profile.
Implementations§
Source§impl ClassifiedCid
impl ClassifiedCid
Sourcepub fn from_cid(cid: Cid) -> Self
pub fn from_cid(cid: Cid) -> Self
Classify an already-parsed Cid. Infallible: every well-formed CID is
exactly one of the three kinds.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, ContentError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, ContentError>
Parse the CID binary envelope and classify.
§Errors
ContentError::InvalidCid if the bytes are not a CID at all. A CID of
a foreign profile is not an error — it is Foreign.
Sourcepub fn is_mintable(&self) -> bool
pub fn is_mintable(&self) -> bool
true for the two profiles this crate mints (Content, Raw).
Sourcepub fn codec(&self) -> u64
pub fn codec(&self) -> u64
The multicodec code of the CID (0x71 dag-cbor, 0x55 raw, or whatever
a foreign CID declares).
Sourcepub fn as_content(&self) -> Option<&ContentId>
pub fn as_content(&self) -> Option<&ContentId>
The ContentId if this is the dag-cbor profile.
Sourcepub fn as_raw(&self) -> Option<&RawContentId>
pub fn as_raw(&self) -> Option<&RawContentId>
The RawContentId if this is the raw profile.
Sourcepub fn as_foreign(&self) -> Option<&ForeignCid>
pub fn as_foreign(&self) -> Option<&ForeignCid>
The ForeignCid if this is neither mintable profile.
Trait Implementations§
Source§impl Clone for ClassifiedCid
impl Clone for ClassifiedCid
Source§fn clone(&self) -> ClassifiedCid
fn clone(&self) -> ClassifiedCid
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ClassifiedCid
Source§impl Debug for ClassifiedCid
impl Debug for ClassifiedCid
Source§impl<'de> Deserialize<'de> for ClassifiedCid
impl<'de> Deserialize<'de> for ClassifiedCid
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Re-classifies from the wire bytes, so the variant is derived rather than trusted — a crafted link cannot land in the wrong variant.
Source§impl Display for ClassifiedCid
impl Display for ClassifiedCid
impl Eq for ClassifiedCid
Source§impl From<ClassifiedCid> for Cid
impl From<ClassifiedCid> for Cid
Source§fn from(v: ClassifiedCid) -> Self
fn from(v: ClassifiedCid) -> Self
Source§impl From<ContentId> for ClassifiedCid
impl From<ContentId> for ClassifiedCid
Source§impl From<ForeignCid> for ClassifiedCid
impl From<ForeignCid> for ClassifiedCid
Source§fn from(id: ForeignCid) -> Self
fn from(id: ForeignCid) -> Self
Source§impl From<RawContentId> for ClassifiedCid
impl From<RawContentId> for ClassifiedCid
Source§fn from(id: RawContentId) -> Self
fn from(id: RawContentId) -> Self
Source§impl FromStr for ClassifiedCid
impl FromStr for ClassifiedCid
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse any multibase CID string and classify. Legacy dialects (kyln
envelope-hex, blake3:<hex>, bare digest hex) are not accepted —
use the explicit legacy adapters.