Skip to main content

ClassifiedCid

Enum ClassifiedCid 

Source
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

Source

pub fn from_cid(cid: Cid) -> Self

Classify an already-parsed Cid. Infallible: every well-formed CID is exactly one of the three kinds.

Source

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.

Source

pub fn as_cid(&self) -> &Cid

Borrow the underlying Cid, whichever variant.

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

The full CID binary envelope, whichever variant.

Source

pub fn is_mintable(&self) -> bool

true for the two profiles this crate mints (Content, Raw).

Source

pub fn codec(&self) -> u64

The multicodec code of the CID (0x71 dag-cbor, 0x55 raw, or whatever a foreign CID declares).

Source

pub fn hash_code(&self) -> u64

The multihash code of the CID (0x1e BLAKE3, 0x12 sha2-256, …).

Source

pub fn as_content(&self) -> Option<&ContentId>

The ContentId if this is the dag-cbor profile.

Source

pub fn as_raw(&self) -> Option<&RawContentId>

The RawContentId if this is the raw profile.

Source

pub fn as_foreign(&self) -> Option<&ForeignCid>

The ForeignCid if this is neither mintable profile.

Trait Implementations§

Source§

impl Clone for ClassifiedCid

Source§

fn clone(&self) -> ClassifiedCid

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ClassifiedCid

Source§

impl Debug for ClassifiedCid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ClassifiedCid

Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The inner CID’s canonical multibase string (base32-lower for CIDv1; a foreign CIDv0 renders as its base58btc form, per the CID spec).

Source§

impl Eq for ClassifiedCid

Source§

impl From<ClassifiedCid> for Cid

Source§

fn from(v: ClassifiedCid) -> Self

Converts to this type from the input type.
Source§

impl From<ContentId> for ClassifiedCid

Source§

fn from(id: ContentId) -> Self

Converts to this type from the input type.
Source§

impl From<ForeignCid> for ClassifiedCid

Source§

fn from(id: ForeignCid) -> Self

Converts to this type from the input type.
Source§

impl From<RawContentId> for ClassifiedCid

Source§

fn from(id: RawContentId) -> Self

Converts to this type from the input type.
Source§

impl FromStr for ClassifiedCid

Source§

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.

Source§

type Err = ContentError

The associated error which can be returned from parsing.
Source§

impl Hash for ClassifiedCid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for ClassifiedCid

Source§

fn cmp(&self, other: &ClassifiedCid) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ClassifiedCid

Source§

fn eq(&self, other: &ClassifiedCid) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for ClassifiedCid

Source§

fn partial_cmp(&self, other: &ClassifiedCid) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for ClassifiedCid

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ClassifiedCid

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.