Skip to main content

TermValue

Enum TermValue 

Source
pub enum TermValue<'a, const INLINE_BYTES: usize> {
    Inline {
        bytes: [u8; INLINE_BYTES],
        len: usize,
    },
    Borrowed(&'a [u8]),
    Stream(&'a dyn ChunkSource),
}
Expand description

Wiki ADR-029 + ADR-060: a single Term variant’s evaluated value, carried as a source-polymorphic carrier const-generic over its inline width. ADR-060 replaces the pre-0.5.0 fixed-4096-byte buffer with three variants:

  • Inline — a stack buffer of INLINE_BYTES (foundation-derived via carrier_inline_bytes) carrying derived structural content: integer literals at any admitted Witt level, cryptographic digests at the application’s hasher output width, the κ-label ASCII form, and primitive-op single-value outputs.
  • Borrowed — a slice into an upstream byte source (input bytes, a sibling ψ-stage’s scratch, an axis-kernel output region). Its carrier width is size_of::<&[u8]>(), independent of payload size.
  • Stream — a chunk-emitting source for unbounded payloads, no ceiling.

INLINE_BYTES is a free const-generic parameter; the application instantiates it at the boundary via carrier_inline_bytes::<MyBounds>() (per the min-const-generics pattern, stable Rust, no generic_const_exprs).

Variants§

§

Inline

Stack-allocated inline buffer (zero-padded beyond len).

Fields

§bytes: [u8; INLINE_BYTES]

Fixed-capacity inline byte buffer.

§len: usize

Active prefix length (<= INLINE_BYTES).

§

Borrowed(&'a [u8])

Borrowed slice into an upstream byte source — no byte-width ceiling.

§

Stream(&'a dyn ChunkSource)

Chunk-emitting source for unbounded payloads — no byte-width ceiling.

Implementations§

Source§

impl<'a, const INLINE_BYTES: usize> TermValue<'a, INLINE_BYTES>

Source

pub const fn empty() -> TermValue<'a, INLINE_BYTES>

Construct an empty inline TermValue (length zero).

Source

pub const fn inline_from_slice(bytes: &[u8]) -> TermValue<'a, INLINE_BYTES>

ADR-060: construct an Inline TermValue by copying up to INLINE_BYTES bytes from bytes. For payloads exceeding the inline width use TermValue::Borrowed / TermValue::Stream instead.

Source

pub const fn borrowed(bytes: &'a [u8]) -> TermValue<'a, INLINE_BYTES>

Construct a zero-copy Borrowed TermValue referencing bytes.

Source

pub const fn stream(source: &'a dyn ChunkSource) -> TermValue<'a, INLINE_BYTES>

Construct a Stream TermValue over an unbounded chunk source.

Source

pub const fn from_u64_be( value: u64, width: usize, ) -> TermValue<'a, INLINE_BYTES>

ADR-051: construct an Inline TermValue from a u64 at a declared byte width.

Source

pub const fn from_inline_const( bytes: &[u8; INLINE_BYTES], len: usize, ) -> TermValue<'a, INLINE_BYTES>

ADR-060: const-constructor from a prepared inline buffer of width INLINE_BYTES.

Source

pub fn as_slice(&self) -> Option<&[u8]>

Returns the active byte prefix for materializable carriers (Inline / Borrowed), or None for Stream (which has no single contiguous slice — read it via TermValue::for_each_chunk).

Source

pub fn bytes(&self) -> &[u8]

Returns the active byte prefix for Inline / Borrowed, or the empty slice for Stream. Structural fold-rules that never produce Stream use this; Stream-aware consumers use TermValue::for_each_chunk.

Source

pub fn for_each_chunk(&self, f: &mut dyn FnMut(&[u8]))

ADR-060: fold every byte of the carrier into f in canonical order, dispatching on the variant — Inline / Borrowed emit a single chunk, Stream delegates to ChunkSource::for_each_chunk. This is the universal reader the σ-projection folds through Hasher::fold_bytes.

Source

pub fn len_hint(&self) -> Option<usize>

Total byte length if known: Inline/Borrowed always; Stream only when its source reports ChunkSource::total_bytes.

Source

pub fn to_vec(&self) -> Vec<u8>

Available on crate feature alloc only.

ADR-060: opt-in, alloc-gated materialization into an owned buffer — the only allocation surface, per caller. Folds every chunk into a Vec<u8> (works for all three variants, including Stream).

Trait Implementations§

Source§

impl<'a, const INLINE_BYTES: usize> Clone for TermValue<'a, INLINE_BYTES>

Source§

fn clone(&self) -> TermValue<'a, INLINE_BYTES>

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<'a, const INLINE_BYTES: usize> Debug for TermValue<'a, INLINE_BYTES>

Source§

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

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

impl<'a, const INLINE_BYTES: usize> PartialEq for TermValue<'a, INLINE_BYTES>

Source§

fn eq(&self, other: &TermValue<'a, INLINE_BYTES>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, const INLINE_BYTES: usize> Copy for TermValue<'a, INLINE_BYTES>

Source§

impl<'a, const INLINE_BYTES: usize> Eq for TermValue<'a, INLINE_BYTES>

Auto Trait Implementations§

§

impl<'a, const INLINE_BYTES: usize> Freeze for TermValue<'a, INLINE_BYTES>

§

impl<'a, const INLINE_BYTES: usize> !RefUnwindSafe for TermValue<'a, INLINE_BYTES>

§

impl<'a, const INLINE_BYTES: usize> !Send for TermValue<'a, INLINE_BYTES>

§

impl<'a, const INLINE_BYTES: usize> !Sync for TermValue<'a, INLINE_BYTES>

§

impl<'a, const INLINE_BYTES: usize> Unpin for TermValue<'a, INLINE_BYTES>

§

impl<'a, const INLINE_BYTES: usize> UnsafeUnpin for TermValue<'a, INLINE_BYTES>

§

impl<'a, const INLINE_BYTES: usize> !UnwindSafe for TermValue<'a, INLINE_BYTES>

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.