Skip to main content

Cap

Enum Cap 

Source
pub enum Cap {
    Instance(InstanceCap),
    Image(ImageCap),
    Data(DataCap),
    CNode(CNodeCap),
    Type(TypeCap),
}
Expand description

One of the five v3 cap kinds.

SSZ note: the HashTreeRoot derive treats Cap as an SSZ Union over the five variants. Each variant’s selector provides the domain separation that the legacy byte-protocol kind tags (0x10..0x50) provided; the per-variant root is computed by that variant’s own HashTreeRoot impl. We do not derive Encode + Decode on Cap itself; caps move through the cache by direct allocation and aren’t wire-transmitted at this layer.

Clone: the derived Clone recursively clones field-by-field. Cap::Instance and Cap::CNode carry CapHashOrRef values; the Ref(CapRef) arm Arc::clones the handle, so cloning a Cap deep-bumps every nested instance reference. Drop is symmetric.

Variants§

§

Instance(InstanceCap)

§

Image(ImageCap)

§

Data(DataCap)

§

CNode(CNodeCap)

§

Type(TypeCap)

Implementations§

Source§

impl Cap

Source

pub fn kind(&self) -> CapKind

Source

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

Build a heap Cap::Data whose content is bytes padded up to the next PAGE_SIZE boundary with zeros. The backing allocation is page-aligned so the kernel can later map the cap’s pages directly into a ring-3 PT.

DataCap.content_len() returns the padded length (always a 4 KiB-multiple). There is no separate logical-size field; callers needing a shorter logical payload (e.g. variable-length args) interpret the meaningful prefix themselves.

Source

pub fn data_inline_with_size(bytes: &[u8], target_size: u64) -> Self

Build a heap Cap::Data whose backing buffer is at least target_size bytes (rounded up to the next page boundary). bytes is copied to the start of the buffer; the remainder is zero-padded. Used by callers that need a cap matching a specific MemoryMapping.size from an image manifest (e.g. genesis + transpiler-emitted initial data).

If target_size < bytes.len(), the buffer is sized to fit bytes (still page-multiple) — i.e. target_size is a floor, not a ceiling.

Source

pub fn image_from(image: &Image) -> Result<Self, ImageConvertError>

Build a heap Cap::Image from a SCALE Image value. Pinned and initial slot references are left empty; callers that need them should drive super::image_cap::image_cap directly with the already-resolved (slot, CapHash) pairs.

Source

pub fn empty_cnode(size_log: u8) -> Result<Self, CapError>

Build an empty heap Cap::CNode of 2^size_log slots. Rejects size_log > 16.

Source

pub fn image_with_slots( image: &Image, pinned_hashes: &[(SlotIdx, CapHash)], initial_hashes: &[(SlotIdx, CapHash)], ) -> Result<Self, ImageConvertError>

Build a heap Cap::Image from a SCALE Image plus the caller-resolved pinned/initial slot CapHash pairs.

Wraps super::image_cap::image_cap with the Cap::Image constructor. Use this when the caller has already published (or knows the hashes of) the pinned/initial data blobs that the image references.

Source

pub fn instance_with_overlays( image_hash_chain: CapHash, image_hash: CapHash, root_cnode: CapHash, rw_overlays: &[(u32, &[u8])], mem_size: u32, regs: [u64; 13], pc: u64, gas_remaining: u64, ) -> Self

Build a heap Cap::Instance directly from field values. Mirrors the shape the old CacheDirectory::publish_instance_blob reconstructed field-by-field but produces a Cap::Instance(InstanceCap) the caller owns.

rw_overlays is the list of (start_va, bytes) overlays the Instance carries — each becomes one RwOverlay entry.

Trait Implementations§

Source§

impl Clone for Cap

Source§

fn clone(&self) -> Cap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cap

Source§

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

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

impl HashTreeRoot for Cap

Source§

fn hash_tree_root<__D: Digest<OutputSize = U32>>(&self) -> [u8; 32]

Compute the hash tree root using D as the underlying hash.

Auto Trait Implementations§

§

impl Freeze for Cap

§

impl RefUnwindSafe for Cap

§

impl Send for Cap

§

impl Sync for Cap

§

impl Unpin for Cap

§

impl UnsafeUnpin for Cap

§

impl UnwindSafe for Cap

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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
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.