pub struct CdynHandle<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’sretaindrop→ calls the plugin’sreleasectx→ the instance pointer (first arg of every vtable method)vtable→&Treconstructed 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 { CdynHandle::<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> CdynHandle<T>
impl<T: Copy> CdynHandle<T>
Sourcepub unsafe fn load(path: &Path, dyn_entry: &[u8]) -> Result<Self>
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
AbiStableDynRefwhose vtable pointer refers to aT-layout vtable.
Sourcepub unsafe fn from_lib(lib: DynLib, dyn_entry: &[u8]) -> Result<Self>
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.
Sourcepub unsafe fn from_raw(raw: AbiStableDynRef) -> Self
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.
Sourcepub fn ctx(&self) -> *mut c_void
pub fn ctx(&self) -> *mut c_void
Instance context pointer — pass as the first argument of vtable methods.
Sourcepub unsafe fn vtable(&self) -> &T
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.
Sourcepub fn as_raw(&self) -> &AbiStableDynRef
pub fn as_raw(&self) -> &AbiStableDynRef
Raw ABI ref (for passing back across the boundary).
Sourcepub fn into_raw(self) -> AbiStableDynRef
pub fn into_raw(self) -> AbiStableDynRef
Consume without calling release (ownership handed back to the plugin).