Skip to main content

Unit

Struct Unit 

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

A single unit of compacted context, addressed by its derivation.

Constructed only by Unit::seal or by admitting a RawUnit. Serialises (so it can be stored and hashed) but does not deserialise (so the admission boundary cannot be walked around).

Implementations§

Source§

impl Unit

Source

pub fn seal( op: Op, source: &[u8], span: Span, root: ContentId, ) -> Result<Self, SealError>

Seal one unit over SOURCE material.

The source bytes are required — not a convenience, the whole point. A unit cannot be minted without the material it addresses, so there is no way to produce one whose elided claim was never computed from anything.

§Errors

SealError::NotMintableInV0 for any operation other than Op::Elide; SealError::UnaddressedSpan for a span covering no bytes; SealError::SpanOutOfSource when the span runs past the source.

Source

pub const fn derivation(&self) -> &Derivation

The addressed fact this unit’s identity is computed over.

Source

pub fn id(&self) -> Result<UnitId, ContentError>

This unit’s address: the id of its Derivation.

§Errors

Propagates an encoding failure from the canonical form.

Source

pub const fn op(&self) -> Op

What was done to the source material.

Source

pub const fn depth(&self) -> u32

Generation provenance depth: 0 for source material, one more per generation.

Source

pub const fn root(&self) -> ContentId

The root event this unit is caused by.

Source

pub const fn life(&self) -> Life

The lifecycle of this unit’s root.

Source

pub const fn is_well_formed(&self) -> bool

The depth bound: depth <= 1.

Source

pub const fn evictable(&self) -> bool

A unit is freely evictable when its root is no longer live.

Deterministic: no grounding check, no model call, no judgement.

Source

pub const fn with_life(self, life: Life) -> Self

Mark this unit’s root as no longer live.

Deliberately does not change Unit::id: lifecycle is a fact about a derivation, not a different derivation.

Source

pub const fn to_raw(&self) -> RawUnit

The transparent form, for encoding to bytes another process will decode.

Trait Implementations§

Source§

impl Clone for Unit

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 ContentAddressable for Unit

Source§

fn canonical_form(&self) -> Result<Vec<u8>, ContentError>

The canonical form is the derivation’s, so a unit’s bytes and its id agree with Unit::id.

Source§

fn content_id(&self) -> Result<ContentId, ContentError>

Compute this value’s ContentId. Read more
Source§

fn verify(&self, expected: &ContentId) -> Result<bool, ContentError>

Check whether this value’s content id matches an expected id. Read more
Source§

fn ensure_content_id(&self, expected: &ContentId) -> Result<(), ContentError>

Verify, returning an error on mismatch instead of Ok(false). Read more
Source§

impl Copy for Unit

Source§

impl Debug for Unit

Source§

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

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

impl Eq for Unit

Source§

impl PartialEq for Unit

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 Unit

A Unit encodes exactly as its RawUnit, so what this process writes is what another process decodes — and what it decodes must then pass admission. Written by hand rather than derived: #[serde(flatten)] over the derivation would be a second, silently different layout, and deny_unknown_fields does not compose with it.

Source§

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

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

impl StructuralPartialEq for Unit

Source§

impl TryFrom<RawUnit> for Unit

Source§

fn try_from(raw: RawUnit) -> Result<Self, Self::Error>

The only way in from foreign bytes.

§Errors

See AdmitError. Span-versus-source is checked by crate::verify, which needs the bytes this function does not have.

Source§

type Error = AdmitError

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl Freeze for Unit

§

impl RefUnwindSafe for Unit

§

impl Send for Unit

§

impl Sync for Unit

§

impl Unpin for Unit

§

impl UnsafeUnpin for Unit

§

impl UnwindSafe for Unit

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> 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 = !

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.