pub enum CapHashOrRef<O = Box<Cap>> {
Hash(CapHash),
Owned(O),
}Expand description
Slot/field reference: a content-addressed blob in cache.blobs
(Hash), or a single-owner cap held inline by the running kernel
frame (Owned).
Owned(Box<Cap>) is the zero-copy ownership form: a cap the
kernel frame owns outright and moves between cnode slots (and between
frames, at HALT) with no cache round-trip and no data copy — the move
is a Box pointer swap. It is runtime-only: it never crosses the
wire and is never hashed. The recompiler mints it on derive_spawn
and moves it through host_call; it never settles one (the
host-side settle arm folds it into a blob for the deferred persist
path).
SSZ note: CapHashOrRef’s HashTreeRoot impl is hand-rolled,
not derived. The pass-through semantics — Hash(h) hashes to h —
let a freshly-published cap substitute for a content reference without
changing the hash of any cap that holds it. The Owned arm panics:
callers must settle a cap graph before hashing it. Encode mirrors
HashTreeRoot (panic on the runtime-only arm); Decode only ever
produces Hash (the wire carries selector 0).
Generic over the owned payload O (default Box<Cap>). The wire
form (the cnode inside a serialised Cap) is always
CapHashOrRef<Box<Cap>>, so Cap and its hash are unaffected. An
engine may instantiate a running frame’s cnode with a richer,
deliberately non-wire payload (e.g. Box<CachedCap>); the
serialisation impls below are gated on O: rkyv::Archive, so such a
payload makes the cnode non-hashable and non-serialisable at compile
time (a strictly stronger guarantee than the runtime Owned panic).
Not Copy: the Owned(O) arm carries the (usually heap-allocated)
payload, so the enum is Clone-only (when O: Clone).
PartialEq/Eq/Hash are hand-written: a Box<Cap> payload
blocks the derive (Cap is not Eq/Hash). The Hash arm
compares/hashes its 32-byte digest by value; the Owned arm uses
pointer identity of the inline payload (sound — Owned is single-owner
runtime state, never content-compared — and O-agnostic, so it needs no
bound).
Variants§
Trait Implementations§
Source§impl<O: WireOwned> Archive for CapHashOrRef<O>
impl<O: WireOwned> Archive for CapHashOrRef<O>
Source§type Archived = <[u8; 32] as Archive>::Archived
type Archived = <[u8; 32] as Archive>::Archived
Source§type Resolver = <[u8; 32] as Archive>::Resolver
type Resolver = <[u8; 32] as Archive>::Resolver
Source§fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize. Read moreSource§impl<O: Clone> Clone for CapHashOrRef<O>
impl<O: Clone> Clone for CapHashOrRef<O>
Source§fn clone(&self) -> CapHashOrRef<O>
fn clone(&self) -> CapHashOrRef<O>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<O: Debug> Debug for CapHashOrRef<O>
impl<O: Debug> Debug for CapHashOrRef<O>
Source§impl<O: WireOwned> Decode for CapHashOrRef<O>
impl<O: WireOwned> Decode for CapHashOrRef<O>
Source§fn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
true iff this type is fixed-length.Source§fn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
BYTES_PER_LENGTH_OFFSET].Source§fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
bytes, rejecting trailing input.Source§impl<O, D> Deserialize<CapHashOrRef<O>, D> for [u8; 32]where
D: Fallible + ?Sized,
impl<O, D> Deserialize<CapHashOrRef<O>, D> for [u8; 32]where
D: Fallible + ?Sized,
Source§fn deserialize(
&self,
_deserializer: &mut D,
) -> Result<CapHashOrRef<O>, <D as Fallible>::Error>
fn deserialize( &self, _deserializer: &mut D, ) -> Result<CapHashOrRef<O>, <D as Fallible>::Error>
Source§impl<O: WireOwned> Encode for CapHashOrRef<O>
impl<O: WireOwned> Encode for CapHashOrRef<O>
Source§fn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
true iff this type is fixed-length (no variable-length fields).Source§fn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
BYTES_PER_LENGTH_OFFSET] (i.e. the size of the offset slot).Source§fn ssz_bytes_len(&self) -> usize
fn ssz_bytes_len(&self) -> usize
self when serialized.Source§fn ssz_append(&self, buf: &mut Vec<u8>)
fn ssz_append(&self, buf: &mut Vec<u8>)
self to buf.§fn is_basic_type() -> bool
fn is_basic_type() -> bool
true for “basic” SSZ types (uintN, bool), which pack adjacent
elements into shared 32-byte chunks for merkleization. Composite
types (containers, lists, structs) return false (the default).§fn as_ssz_bytes(&self) -> Vec<u8> ⓘ
fn as_ssz_bytes(&self) -> Vec<u8> ⓘ
Vec<u8> allocated through the global allocator.Source§impl<O> Hash for CapHashOrRef<O>
impl<O> Hash for CapHashOrRef<O>
Source§impl<O: WireOwned> HashTreeRoot for CapHashOrRef<O>
impl<O: WireOwned> HashTreeRoot for CapHashOrRef<O>
Source§impl<O> PartialEq for CapHashOrRef<O>
impl<O> PartialEq for CapHashOrRef<O>
Source§impl<O, S> Serialize<S> for CapHashOrRef<O>
impl<O, S> Serialize<S> for CapHashOrRef<O>
impl<O> Eq for CapHashOrRef<O>
Auto Trait Implementations§
impl<O> Freeze for CapHashOrRef<O>where
O: Freeze,
impl<O> RefUnwindSafe for CapHashOrRef<O>where
O: RefUnwindSafe,
impl<O> Send for CapHashOrRef<O>where
O: Send,
impl<O> Sync for CapHashOrRef<O>where
O: Sync,
impl<O> Unpin for CapHashOrRef<O>where
O: Unpin,
impl<O> UnsafeUnpin for CapHashOrRef<O>where
O: UnsafeUnpin,
impl<O> UnwindSafe for CapHashOrRef<O>where
O: UnwindSafe,
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read more