Skip to main content

ErasedObject

Struct ErasedObject 

Source
#[doc(hidden)]
#[repr(C)]
pub struct ErasedObject<T> { erased: mx_erased, data: RefCell<T>, }
Expand description

Storage used by generated trait-ABI constructors.

The C header and concrete value retain their repr(C) layout. Keeping the allocation and destructor here avoids emitting identical helper items for every ExternalPtr derive. This is not ordinary ExternalPtr/Any storage, but it keeps the value in a RefCell the same way: the method shims borrow it for each call.

Fields§

§erased: mx_erased§data: RefCell<T>

Implementations§

Source§

impl<T> ErasedObject<T>

Source

pub const DATA_OFFSET: usize

Offset of the value’s RefCell, used by trait views, including over-aligned concrete types.

Source

pub unsafe fn into_raw(data: T, base: &'static mx_base_vtable) -> *mut mx_erased

Allocate an erased object with the generated type’s base vtable.

§Safety

base must describe T in this storage: its destructor must be Self::drop_raw, its offset Self::DATA_OFFSET, and its query/tag must identify the trait implementations of this concrete T.

Source

pub unsafe extern "C" fn drop_raw(ptr: *mut mx_erased)

Destructor installed in generated base vtables.

§Safety

A non-null ptr must be a live allocation returned by ErasedObject::<T>::into_raw, and must be released exactly once.

Source§

impl<T: TypedExternal> ErasedObject<T>

Source

const SIDECAR_INIT: SidecarInitVTable

Source

pub unsafe extern "C" fn query( ptr: *mut mx_erased, tag: mx_tag, ) -> *const c_void

Query the concrete type’s traits and its optional sidecar initializer.

§Safety

ptr must be a live ErasedObject<T> with its matching base vtable. The returned pointer is valid for the program’s lifetime and must be cast to the interface identified by tag.

Source

unsafe extern "C-unwind" fn init_sidecars( ptr: *mut mx_erased, owner: SEXP, )

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.