Skip to main content

PluginRegistry

Struct PluginRegistry 

Source
pub struct PluginRegistry<R: Reactor> { /* private fields */ }
Expand description

Manages loaded plugins and their actor type factories.

PluginRegistry is the single source of truth for which plugins are loaded and which actor types they export. It does not interact with the engine directly — callers are responsible for stopping any running actors before calling unload.

Implementations§

Source§

impl<R: Reactor> PluginRegistry<R>

Source

pub fn load_native(&mut self, path: &Path) -> Result<PluginInfo, PluginError>

Load a native shared library plugin from path.

Steps:

  1. Open the library with libloading.
  2. Resolve all required C symbols; fail fast on missing exports.
  3. Call pd_plugin_init and verify the returned ABI version.
  4. For each declared actor type, register a factory that constructs an [FfiActor] wrapping the plugin’s lifecycle functions.
  5. Record the loaded library in the registry so it stays mapped in memory for the lifetime of the actors it created.

Returns PluginInfo describing the newly loaded plugin.

§Errors
Source§

impl<R: Reactor> PluginRegistry<R>

Source

pub fn new() -> Self

Create an empty registry with no loaded plugins.

Source

pub fn list(&self) -> Vec<PluginInfo>

List metadata for all currently loaded plugins, sorted by name.

Source

pub fn create_actor( &self, type_name: &str, config: &[u8], ) -> Result<Box<dyn Actor<R>>, PluginError>

Create an actor instance from a registered type.

config is an opaque byte slice forwarded to the factory; pass &[] for types that require no configuration.

Returns Err(PluginError::UnknownType(...)) if no factory is registered for type_name.

Source

pub fn actor_types_for_plugin(&self, plugin_name: &str) -> Vec<String>

Return actor type names registered by a specific plugin, sorted.

Source

pub fn unload(&mut self, name: &str) -> Result<(), PluginError>

Unload a plugin by name.

Removes all actor type factories that belong to name from the registry, then drops the plugin’s library handle (for native plugins, this calls dlclose).

Caller’s responsibility: stop all running actors created by this plugin before calling unload. Dropping the native library while actors are still executing code from it is undefined behaviour.

Returns Err(PluginError::UnknownType(...)) if no plugin named name is loaded.

Source

pub fn register_type( &mut self, plugin_name: impl Into<String>, type_name: impl Into<String>, factory: impl Fn(&[u8]) -> Result<Box<dyn Actor<R>>, PluginError> + Send + Sync + 'static, )

Register an actor type factory.

Called internally by load_native and load_wasm after reading plugin metadata.

Can also be used for programmatic (in-process) plugin registration — for example, registering test actors without loading a shared library. Note that register_type alone does not add an entry to list; the plugin must also be recorded via insert_loaded to appear there.

Source

pub fn load_wasm( &mut self, path: &Path, host: Arc<dyn WasmHost>, ) -> Result<PluginInfo, PluginError>

Load a WASM plugin from path, using host to compile and inspect it.

Protocol:

  1. Read .wasm bytes from path.
  2. Compile via host.compile.
  3. Instantiate with no-op imports (metadata pass).
  4. Call the module’s pd_plugin_init() -> i32 export, which returns a pointer into WASM linear memory where a WASM-layout PdPluginInfo struct is stored (32-bit pointer fields).
  5. Parse the struct to extract name, version, ABI version, and actor type names. Reject mismatched ABI.
  6. Register a WasmActor factory for each declared actor type.

Trait Implementations§

Source§

impl<R: Reactor> Default for PluginRegistry<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> Freeze for PluginRegistry<R>

§

impl<R> !RefUnwindSafe for PluginRegistry<R>

§

impl<R> Send for PluginRegistry<R>

§

impl<R> Sync for PluginRegistry<R>

§

impl<R> Unpin for PluginRegistry<R>

§

impl<R> UnsafeUnpin for PluginRegistry<R>

§

impl<R> !UnwindSafe for PluginRegistry<R>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

Source§

fn upcast(self) -> T

Source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

Source§

fn upcast_from(value: Counter<T, B>) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V