Skip to main content

Module native

Module native 

Source
Expand description

§dyn — Rust fat-pointer bridge for trait objects

Load trait objects from .so/.dylib plugins using Rust’s native fat-pointer representation (data pointer + vtable pointer), wrapped with Arc-like retain/release for cross-boundary memory safety.

This module follows the two cross-module invariants shared by all modes of this crate (see [crate::cdyn] for the full statement):

  1. Whoever allocates, deallocates — the plugin’s retain/release function pointers execute inside the plugin module (for Rust plugins they wrap Arc ref-count ops on the plugin’s own heap allocation).
  2. Whoever creates, operates — the host receives the fat pointer and calls through it; every method dispatch goes through the vtable the plugin created, executing plugin-side code.
  • AbiDynFatPtr: ABI-stable representation of a Rust fat pointer, #[repr(C)] for C ABI compatibility.
  • AbiStableDynRef: fat pointer + retain/release function pointers.
  • SafeArcDyn: safe, cloneable handle over an AbiStableDynRef.
  • NativeModule: loaded plugin dereferencing to &T.

§Usage

// In the plugin .so:
#[no_mangle]
pub extern "C" fn core_ast_transform_entry() -> AbiStableDynRef {
    SafeArcDyn::from_arc(Arc::new(MyTransform) as Arc<dyn Transform>).into_abi()
}

// In the host:
use dyn_loader::dyn_mod::{NativeModule, AbiStableDynRef, SafeArcDyn};
let plugin = NativeModule::<dyn Transform>::load("libmy_transform.so", b"core_ast_transform_entry\0")?;
let transform: &dyn Transform = plugin.trait_ref();

Structs§

AbiDynFatPtr
ABI-stable representation of a Rust dyn trait fat pointer. Two words: data pointer + vtable pointer.
AbiStableDynRef
ABI-stable reference to a dyn trait object, with retain/release for safe reference counting across dynamic library boundaries.
NativeModule
A loaded dynamic library plugin that exposes a trait object via the dyn-fat-pointer-bridge pattern.
SafeArcDyn
A safe, cloneable, droppable reference to a dyn trait object loaded from a dynamic library. Uses Arc-like retain/release for memory safety.

Functions§

pack_fat_ptr
Pack a *const T (where T: ?Sized) into an ABI-stable fat pointer.
unpack_fat_ptr
Unpack an ABI-stable fat pointer back to *const T.

Type Aliases§

ModuleDynEntryPoint
Type of the entry point function that plugins must export.
ReleaseFn
RetainFn