Skip to main content

OwnedClosureBlock

Struct OwnedClosureBlock 

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

Owning handle for a raw TypedClosureHeader block paired with its layout.

§Closure spec §14.6 (H6.5)

Wraps a *const TypedClosureHeader returned by alloc_typed_closure alongside the Arc<ClosureLayout> needed to decode/release its captures. Clone bumps the block’s refcount via retain_typed_closure; Drop decrements via release_typed_closure so ownership mirrors the Arc<HeapValue> convention used by every other heap-backed value.

The raw pointer is stashed as *const u8 internally (erased) because TypedClosureHeader is !Send + !Sync; the owner’s manual unsafe impl Send + Sync is justified by the fact that the block itself is immutable (refcount aside) and the layout is already Send + Sync via Arc.

§Safety invariant

For every live OwnedClosureBlock, ptr was allocated by alloc_typed_closure with the exact layout carried in this owner, and the block is refcount-owned by this instance.

Implementations§

Source§

impl OwnedClosureBlock

Source

pub unsafe fn from_raw(ptr: *const u8, layout: Arc<ClosureLayout>) -> Self

Construct an OwnedClosureBlock from a freshly-allocated raw pointer. The caller transfers exactly one refcount share.

§Safety
Source

pub fn as_ptr(&self) -> *const u8

Borrow the underlying raw pointer. The returned pointer is live for at least as long as self.

Source

pub fn as_header_ptr(&self) -> *const TypedClosureHeader

Borrow the underlying raw pointer typed as TypedClosureHeader.

Source

pub fn layout(&self) -> &Arc<ClosureLayout>

Borrow the layout that describes this block’s captures. Shared with the program’s closure_function_layouts side-table; clones are cheap Arc bumps.

Source

pub unsafe fn read_capture_kinded(&self, idx: usize) -> (u64, NativeKind)

Read capture idx’s raw 8-byte payload paired with its NativeKind from the layout’s per-capture kind track (ADR-006 §2.7.8 / Q10).

This is the cell-bound mirror of the §2.7.7 stack-side read_owned_kinded accessor: returns (bits, kind) lockstep so the caller can route through clone_with_kind / drop_with_kind (the canonical KindedSlot dispatch) without reconstructing the kind from the slot bits or probing a tag.

For Immutable captures the returned bits are the raw payload bit pattern (e.g. f64::to_bits(v), Arc::into_raw::<T> raw pointer) and kind classifies it directly.

For OwnedMutable and Shared captures the returned bits are the raw cell pointer (*mut T from Box::into_raw or *const SharedCell from Arc::into_raw); kind classifies the cell’s interior payload — the same shape capture_inner_kind resolves to at the FieldKind level, but lifted to NativeKind so heap-bearing interior payloads dispatch through the same table the stack-tier uses. Wave-β B6-variables-loadptr consumes this accessor to migrate the Load*Ptr / Store*Ptr handlers off NotImplemented(SURFACE).

§Safety

The block’s captures area for idx must have been initialised (zero-initialised by alloc_typed_closure and then written by the make-closure init stage). The 8-byte read is always in-bounds because the layout rounds total size up to 8-byte alignment and idx < layout.capture_count().

§Panics

Panics if idx >= self.layout.capture_count().

Trait Implementations§

Source§

impl Clone for OwnedClosureBlock

Source§

fn clone(&self) -> Self

Bumps the block’s refcount and the layout Arc’s refcount.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OwnedClosureBlock

Source§

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

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

impl Drop for OwnedClosureBlock

Source§

fn drop(&mut self)

Releases the block’s refcount share. If this was the last share the block is walked (heap_capture_mask bits drop their shares) and deallocated. The layout Arc is decremented by the default field-drop below.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for OwnedClosureBlock

Source§

impl Sync for OwnedClosureBlock

Auto Trait Implementations§

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 = 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.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,