Skip to main content

Payload

Struct Payload 

Source
pub struct Payload<T: Copy> { /* private fields */ }
Expand description

A descriptor together with the Rust type of the payload it describes.

TypeDescriptor::builtin takes the payload type P, derives size/align from it, and then erases it. An allocator that took the payload as a bare generic could therefore only compare widths at runtimegc_alloc(ctx, &scalars::INT, 0) passes an i32, because Rust’s default integer type is not i64, and aborts the process with “payload size mismatch for descriptor Int” from inside extern "C". That is the non-unwinding panic across the ABI §10.4 forbids, and it cannot fire until the wrong call runs.

Payload<T> re-attaches the type. The pairing is checked once, where the handle is declared — Payload::new is a const fn whose assertions run during const evaluation, so a static/const handle whose T is not its descriptor’s payload fails to compile. And because the allocators take the handle and the value together, the value’s type is checked at every call site by ordinary type inference. Neither mistake reaches a runtime assert.

Implementations§

Source§

impl<T: Copy> Payload<T>

Source

pub const fn new(descriptor: &'static TypeDescriptor) -> Payload<T>

Pair descriptor with the payload type T.

Declare the result as a const or static — that is what makes the check a compile-time one. Called in a runtime expression the assertions are ordinary ones, which is the situation this type exists to remove.

§Panics

During const evaluation, if T’s layout is not the one descriptor declares.

Source

pub const fn descriptor(self) -> &'static TypeDescriptor

The descriptor this handle carries. Its address is the type’s identity, and the handle holds the one static, so that identity survives.

Source

pub unsafe fn read(self, payload: *const u8) -> T

Read the payload at payload as this handle’s T.

The width is the compiler’s: it is size_of::<T>(), and Payload::new proved during const evaluation that that is exactly the descriptor’s declared width. A caller therefore cannot pick a width, and cannot pick the wrong one — a hand-written read of a one-byte Bool through an i64 consumes seven bytes of arena padding the allocator never initialized.

This is the read half of what Payload<T> already does for allocation. It does not check the object’s descriptor — a handle names a type but a raw payload pointer carries no header — so callers that hold a GcRef should reach for the wrapper that checks identity first.

§Safety

payload must point at an initialized payload of this handle’s type, aligned for T.

Trait Implementations§

Source§

impl<T: Copy> Clone for Payload<T>

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<T: Copy> Copy for Payload<T>

Source§

impl<T: Copy> Debug for Payload<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Payload<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for Payload<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for Payload<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for Payload<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for Payload<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Payload<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Payload<T>
where PhantomData<fn() -> T>: UnwindSafe,

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.