#[repr(C)]pub struct mx_base_vtable {
pub drop: unsafe extern "C" fn(ptr: *mut mx_erased),
pub concrete_tag: mx_tag,
pub query: unsafe extern "C" fn(ptr: *mut mx_erased, trait_tag: mx_tag) -> *const c_void,
pub data_offset: usize,
}Expand description
Base vtable present in all erased objects.
This vtable provides the minimal operations needed for any erased object:
- Destructor for cleanup when R garbage collects the wrapper
- Concrete type tag for type-safe downcasts
- Query function to retrieve interface vtables
§Layout Guarantee
This type is #[repr(C)] and its layout is frozen. Fields will never
be reordered, and new fields will only be appended at the end.
§Generated By
#[derive(ExternalPtr)] emits a static instance of this vtable for each
wrapped type.
Fields§
§drop: unsafe extern "C" fn(ptr: *mut mx_erased)Destructor called when the R external pointer is garbage collected.
Receives a pointer to the erased object (not the data pointer). Must deallocate the entire erased wrapper structure.
§Safety
ptrmust be a valid pointer tomx_erasedallocated by this type’s constructor- Must only be called once per object
- Must be called on R’s main thread (during GC finalization)
concrete_tag: mx_tagTag identifying the concrete type wrapped by this object.
Used for type-safe downcasts: if concrete_tag matches the expected
type’s tag, the data pointer can be cast to that type.
query: unsafe extern "C" fn(ptr: *mut mx_erased, trait_tag: mx_tag) -> *const c_voidQuery function to retrieve interface vtables.
Given a trait tag, returns a pointer to the vtable for that interface, or null if the type does not implement that trait.
§Arguments
ptr- Pointer to the erased objecttrait_tag- Tag identifying the requested trait interface
§Returns
- Non-null pointer to the trait’s vtable if implemented
- Null pointer if the trait is not implemented
§Safety
ptrmust be a valid pointer tomx_erased- The returned pointer (if non-null) must be cast to the correct vtable type
data_offset: usizeByte offset from the start of the wrapper struct to the data field.
The generated wrapper struct is #[repr(C)] struct { erased: mx_erased, data: T }.
When T has stricter alignment than mx_erased, padding exists between
erased and data. This field records the correct offset so that
TraitView::try_from_sexp can compute the data pointer without
assuming offset == size_of::<mx_erased>().