pub struct CidComponents {
pub version: u8,
pub codec: u8,
pub hash_function: u8,
pub hash_length: u8,
pub digest: Vec<u8>,
}Expand description
Parsed components of an IPFS Content Identifier (CID).
A CID encodes four header fields followed by the raw hash digest:
┌─────────┬───────┬──────────────┬────────────┬──────────────┐
│ version │ codec │ hash_function│ hash_length│ digest │
│ (1 B) │ (1 B) │ (1 B) │ (1 B) │ (N bytes) │
└─────────┴───────┴──────────────┴────────────┴──────────────┘Use parse_cid to obtain this from a multibase string, or
decode_cid to obtain it from raw bytes.
§Example
use cow_app_data::{appdata_hex_to_cid, parse_cid};
let hex = "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890";
let cid = appdata_hex_to_cid(hex).unwrap();
let components = parse_cid(&cid).unwrap();
assert_eq!(components.version, 0x01); // CIDv1
assert_eq!(components.codec, 0x55); // raw multicodec
assert_eq!(components.hash_function, 0x1b); // keccak256
assert_eq!(components.hash_length, 0x20); // 32 bytes
assert_eq!(components.digest.len(), 32);Fields§
§version: u8CID version (e.g. 1 for CIDv1).
codec: u8Multicodec code (e.g. 0x55 for raw, 0x70 for dag-pb).
hash_function: u8Multihash function code (e.g. 0x1b for keccak256, 0x12 for sha2-256).
hash_length: u8Hash digest length in bytes (typically 32).
digest: Vec<u8>The raw hash digest bytes.
Trait Implementations§
Source§impl Clone for CidComponents
impl Clone for CidComponents
Source§fn clone(&self) -> CidComponents
fn clone(&self) -> CidComponents
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CidComponents
impl RefUnwindSafe for CidComponents
impl Send for CidComponents
impl Sync for CidComponents
impl Unpin for CidComponents
impl UnsafeUnpin for CidComponents
impl UnwindSafe for CidComponents
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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