Skip to main content

AbiRef

Struct AbiRef 

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

Ref-counted handle to a foreign plugin object exposed through a *_get_dyn style entry point returning an AbiStableDynRef.

This is the Rust-side counterpart of the C++ SDK’s CdynExposed / CdynPlugin and the Zig SDK’s CdynPlugin(PluginType):

  • clone → calls the plugin’s retain
  • drop → calls the plugin’s release
  • ctx → the instance pointer (first arg of every vtable method)
  • vtable&T reconstructed from the packed vtable pointer

T is the C-layout vtable struct (#[repr(C)], Copy) — e.g. MathModuleVtable or your own. The vtable is not copied; it is referenced through the pointer packed inside the dyn ref (it points into the plugin’s static storage, valid while the library stays loaded).

§Example

// C++ plugin built with: CDYN_EXPOSE_CLASS(MathPlugin, MathModuleVtable, math)
// exports: math_get_vtable() and math_get_dyn()
let handle = unsafe { AbiRef::<MathModuleVtable>::load(&path, b"math_get_dyn\0")? };
let vt = unsafe { handle.vtable() };
let session = unsafe { (vt.create_session)() };
let sum = unsafe { (vt.add_i32)(session, 1, 2) };
unsafe { (vt.destroy_session)(session) };
// handle drop → plugin release()

Implementations§

Source§

impl<T: Copy> AbiRef<T>

Source

pub unsafe fn load(path: &Path, dyn_entry: &[u8]) -> Result<Self>

Load a foreign plugin object via its dyn entry point.

§Safety
  • The target file must be a valid dynamic library.
  • The entry must return a valid AbiStableDynRef whose vtable pointer refers to a T-layout vtable.
Source

pub unsafe fn from_lib(lib: DynLib, dyn_entry: &[u8]) -> Result<Self>

Load from an already-loaded library.

§Safety

The entry must return a valid AbiStableDynRef whose vtable pointer refers to a T-layout vtable.

Source

pub unsafe fn from_raw(raw: AbiStableDynRef) -> Self

Reconstruct from a raw AbiStableDynRef obtained elsewhere.

The handle does not own the originating library; the caller must keep it loaded (e.g. hold another DynPlugin or DynLib) for as long as this handle lives.

§Safety

raw must be a live ref produced by a compatible plugin.

Source

pub fn ctx(&self) -> *mut c_void

Instance context pointer — pass as the first argument of vtable methods.

Source

pub unsafe fn vtable(&self) -> &T

The vtable, reconstructed from the pointer packed inside the dyn ref.

§Safety

T must be the exact vtable type the plugin used when building the ref.

Source

pub fn as_raw(&self) -> &AbiStableDynRef

Raw ABI ref (for passing back across the boundary).

Source

pub fn into_raw(self) -> AbiStableDynRef

Consume without calling release (ownership handed back to the plugin).

Trait Implementations§

Source§

impl<T: Copy> Clone for AbiRef<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> Drop for AbiRef<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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<T: Copy + Send> Send for AbiRef<T>

Source§

impl<T: Copy + Sync> Sync for AbiRef<T>

Auto Trait Implementations§

§

impl<T> Freeze for AbiRef<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for AbiRef<T>

§

impl<T> Unpin for AbiRef<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for AbiRef<T>

§

impl<T> UnwindSafe for AbiRef<T>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.