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
impl Unit
Sourcepub fn seal(
op: Op,
source: &[u8],
span: Span,
root: ContentId,
) -> Result<Self, SealError>
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.
Sourcepub const fn derivation(&self) -> &Derivation
pub const fn derivation(&self) -> &Derivation
The addressed fact this unit’s identity is computed over.
Sourcepub fn id(&self) -> Result<UnitId, ContentError>
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.
Sourcepub const fn depth(&self) -> u32
pub const fn depth(&self) -> u32
Generation provenance depth: 0 for source material, one more per generation.
Sourcepub const fn is_well_formed(&self) -> bool
pub const fn is_well_formed(&self) -> bool
The depth bound: depth <= 1.
Sourcepub const fn evictable(&self) -> bool
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.
Trait Implementations§
Source§impl ContentAddressable for Unit
impl ContentAddressable for Unit
Source§fn canonical_form(&self) -> Result<Vec<u8>, ContentError>
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>
fn content_id(&self) -> Result<ContentId, ContentError>
Source§fn verify(&self, expected: &ContentId) -> Result<bool, ContentError>
fn verify(&self, expected: &ContentId) -> Result<bool, ContentError>
expected id. Read moreSource§fn ensure_content_id(&self, expected: &ContentId) -> Result<(), ContentError>
fn ensure_content_id(&self, expected: &ContentId) -> Result<(), ContentError>
Ok(false). Read moreimpl Copy for Unit
impl Eq for Unit
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.
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.
impl StructuralPartialEq for Unit
Source§impl TryFrom<RawUnit> for Unit
impl TryFrom<RawUnit> for Unit
Source§fn try_from(raw: RawUnit) -> Result<Self, Self::Error>
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.