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):
- Whoever allocates, deallocates — the plugin’s
retain/releasefunction pointers execute inside the plugin module (for Rust plugins they wrapArcref-count ops on the plugin’s own heap allocation). - 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§
- AbiDyn
FatPtr - ABI-stable representation of a Rust dyn trait fat pointer. Two words: data pointer + vtable pointer.
- AbiStable
DynRef - ABI-stable reference to a dyn trait object, with retain/release for safe reference counting across dynamic library boundaries.
- Native
Module - A loaded dynamic library plugin that exposes a trait object via the dyn-fat-pointer-bridge pattern.
- Safe
ArcDyn - 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§
- Module
DynEntry Point - Type of the entry point function that plugins must export.
- Release
Fn - Retain
Fn