Skip to main content

mx_base_vtable

Struct mx_base_vtable 

Source
#[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

  • ptr must be a valid pointer to mx_erased allocated 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_tag

Tag 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_void

Query 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 object
  • trait_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

  • ptr must be a valid pointer to mx_erased
  • The returned pointer (if non-null) must be cast to the correct vtable type
§data_offset: usize

Byte 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>().

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> 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, 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.