Skip to main content

Crate dyn_loader

Crate dyn_loader 

Source
Expand description

§dyn-loader

Dynamic library loader with two plugin-loading modes:

§[dyn] — Rust fat-pointer bridge (trait objects)

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

// 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::{DynPlugin, AbiStableDynRef};
let plugin = DynPlugin::<dyn Transform>::load("libmy_transform.so", b"core_ast_transform_entry\0")?;
let transform: &dyn Transform = plugin.trait_ref();

§cdyn — COM-style C function tables (ABI-stable)

Load plain C function-table structs (#[repr(C)] Copy types) via positional dispatch — no trait objects, stable across languages and (to a large extent) compiler versions. This is the former cdyn-loader crate, merged here as VTablePlugin<T>.

let plugin = unsafe { VTablePlugin::<MyVtable>::load("libmy.so", b"my_get_vtable\0")? };

§⚠️ ABI compatibility / compiler version alignment

Even though cdyn mode is layout-stable, the Rust compiler version must still be strictly aligned across all libraries and executables that exchange pointers across the boundary. Pin one toolchain (e.g. via rust-toolchain.toml) and rebuild everything together. See the README for the full cross-version compatibility matrix.

Re-exports§

pub use dyn_mod::AbiDynFatPtr;
pub use dyn_mod::AbiStableDynRef;
pub use dyn_mod::DynPlugin;
pub use dyn_mod::PluginEntryPoint;
pub use dyn_mod::ReleaseFn;
pub use dyn_mod::RetainFn;
pub use dyn_mod::SafeArcDyn;
pub use dyn_mod::pack_fat_ptr;
pub use dyn_mod::unpack_fat_ptr;
pub use cdyn::CdynHandle;
pub use cdyn::GeneratedFunction;
pub use cdyn::MathModuleVtable;
pub use cdyn::MathSession;
pub use cdyn::PluginDynEntryPoint;
pub use cdyn::VTablePlugin;

Modules§

cdyn
cdyn — COM-style C function-table loading (ABI-stable)
dyn_mod
dyn — Rust fat-pointer bridge for trait objects

Structs§

DynLib

Functions§

looks_like_plugin
Quick check: does the file look like a plugin with the given entry symbol?