Skip to main content

Hash

Struct Hash 

Source
pub struct Hash { /* private fields */ }
Expand description

Content hash, multihash-aware: a digest tagged with the function that produced it. BLAKE3-256 today (32 bytes). The string form is <fn>:<hex> (human-inspectable, the Display form); the binary form (to_multihash_bytes) is a self-describing multihash (uvarint(code) ++ uvarint(len) ++ digest).

Implementations§

Source§

impl Hash

Source

pub fn of(bytes: &[u8]) -> Self

Compute the BLAKE3 hash of a byte slice.

Source

pub fn from_chunks<'a, I: IntoIterator<Item = &'a [u8]>>(chunks: I) -> Self

Compute the BLAKE3 hash by streaming chunks through the incremental hasher. Avoids materialising the full payload as a single contiguous slice — useful for verifying large model weights or other multi-MB blobs that arrive in chunks.

ⓘ
let hash = Hash::from_chunks([b"first ", b"second"].into_iter());
assert_eq!(hash, Hash::of(b"first second"));
Source

pub fn from_reader<R: Read>(reader: R) -> Result<Self>

Compute the BLAKE3 hash by streaming bytes from a Read source — e.g. a file handle or HTTP response body. Reads in 64 KiB chunks until EOF.

This is the path that lets eidetic-side verification scale to multi-GiB blobs without holding the full payload in memory at once: pair it with a BlobFetcher that streams.

Source

pub fn func(&self) -> HashFn

The hash function that produced this digest.

Source

pub fn as_bytes(&self) -> &[u8; 32]

The raw digest bytes (no function tag). BLAKE3 is 32 bytes.

Source

pub fn to_hex(&self) -> String

Hex-encoded digest (no algorithm prefix). For the self-describing form use Display (<fn>:<hex>).

Source

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

Self-describing binary multihash: uvarint(multicodec) ++ uvarint(len) ++ digest. Digest fields on the wire, in the event DAG, and in capability scopes should use this form so a hash migration never needs a flag day.

Source

pub fn from_multihash_bytes(bytes: &[u8]) -> Result<Self, HashError>

Parse a [Hash] from its self-describing binary multihash form.

Source

pub fn parse(s: &str) -> Result<Self, HashError>

Parse a [Hash] from its string form <fn>:<hex>. A bare hex string (no <fn>: prefix) is accepted as legacy BLAKE3 for backward reads.

Trait Implementations§

Source§

impl Clone for Hash

Source§

fn clone(&self) -> Self

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 Hash

Source§

impl Debug for Hash

Source§

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

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

impl<'de> Deserialize<'de> for Hash

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Hash

Source§

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

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

impl Eq for Hash

Source§

impl Hash for Hash

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 PartialEq for Hash

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Hash

Source§

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

Serialize as the self-describing string <fn>:<hex> so manifests stay human-inspectable and the hash function travels with the digest.

Source§

impl StructuralPartialEq for Hash

Auto Trait Implementations§

§

impl Freeze for Hash

§

impl RefUnwindSafe for Hash

§

impl Send for Hash

§

impl Sync for Hash

§

impl Unpin for Hash

§

impl UnsafeUnpin for Hash

§

impl UnwindSafe for Hash

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more