pub trait Manager<'a, O: Send + Sync, I: Info>: Send + Sync {
// Required methods
fn format(&self) -> &'static str;
fn register_plugin(
&mut self,
_context: RegisterPluginContext<'_>,
) -> ManagerResult<I>;
// Provided methods
fn register_manager(&mut self) -> ManagerResult<()> { ... }
fn unregister_manager(&mut self) -> ManagerResult<()> { ... }
fn unregister_plugin(
&mut self,
_plugin: &Plugin<'a, O, I>,
) -> ManagerResult<()> { ... }
fn load_plugin(
&mut self,
_context: LoadPluginContext<'a, '_, O, I>,
_api: Api<O, I>,
) -> ManagerResult<()> { ... }
fn unload_plugin(&mut self, _plugin: &Plugin<'a, O, I>) -> ManagerResult<()> { ... }
}
Expand description
Trait for implementing custom plugin managers.
A plugin manager is responsible for handling plugins of a specific format (e.g., Lua, Rust, WASM). It provides the interface between the Plux engine and the actual plugin execution environment.
§Type Parameters
'a
- Lifetime parameter for references within the managerO
- Output type for plugin functions (must implement Send + Sync)I
- Plugin information type (must implement Info trait)
§Example
use plux_rs::{Manager, LoadPluginContext, RegisterPluginContext, Api, Plugin, StdInfo, utils::ManagerResult, function::FunctionOutput};
struct MyManager;
impl<'a> Manager<'a, FunctionOutput, StdInfo> for MyManager {
fn format(&self) -> &'static str {
"my_format"
}
fn register_plugin(&mut self, context: RegisterPluginContext) -> ManagerResult<StdInfo> {
// Implementation for registering a plugin
Ok(StdInfo {
depends: vec![],
optional_depends: vec![],
})
}
}
Required Methods§
Sourcefn format(&self) -> &'static str
fn format(&self) -> &'static str
Returns the file format/extension this manager handles (e.g., “lua”, “rs”, “wasm”).
This format is used to identify which manager should handle a particular plugin file.
Sourcefn register_plugin(
&mut self,
_context: RegisterPluginContext<'_>,
) -> ManagerResult<I>
fn register_plugin( &mut self, _context: RegisterPluginContext<'_>, ) -> ManagerResult<I>
Registers a plugin with this manager.
This method is called when a plugin file matching this manager’s format is discovered. The manager should validate the plugin and return information about it.
§Parameters
context
- Context containing plugin path and bundle information
§Returns
Returns ManagerResult<I>
containing plugin information on success.
Provided Methods§
Sourcefn register_manager(&mut self) -> ManagerResult<()>
fn register_manager(&mut self) -> ManagerResult<()>
Called when the manager is registered with the loader.
This is the place to perform any initialization required by the manager. Default implementation does nothing and returns Ok(()).
§Returns
Returns ManagerResult<()>
indicating success or failure of manager registration.
Sourcefn unregister_manager(&mut self) -> ManagerResult<()>
fn unregister_manager(&mut self) -> ManagerResult<()>
Called when the manager is unregistered from the loader.
This is the place to perform any cleanup required by the manager. Default implementation does nothing and returns Ok(()).
§Returns
Returns ManagerResult<()>
indicating success or failure of manager unregistration.
Sourcefn unregister_plugin(&mut self, _plugin: &Plugin<'a, O, I>) -> ManagerResult<()>
fn unregister_plugin(&mut self, _plugin: &Plugin<'a, O, I>) -> ManagerResult<()>
Unregisters a plugin from this manager.
This method is called when a plugin is being removed from the system. Default implementation does nothing and returns Ok(()).
§Parameters
plugin
- Reference to the plugin being unregistered
§Returns
Returns ManagerResult<()>
indicating success or failure of plugin unregistration.
Sourcefn load_plugin(
&mut self,
_context: LoadPluginContext<'a, '_, O, I>,
_api: Api<O, I>,
) -> ManagerResult<()>
fn load_plugin( &mut self, _context: LoadPluginContext<'a, '_, O, I>, _api: Api<O, I>, ) -> ManagerResult<()>
Loads a plugin into the execution environment.
This method is called after plugin registration and is responsible for making the plugin available for execution. This typically involves loading the plugin code, registering functions, and setting up the execution context.
Default implementation does nothing and returns Ok(()).
§Parameters
context
- Context containing plugin and loader informationapi
- API interface for interacting with the host application
§Returns
Returns ManagerResult<()>
indicating success or failure of plugin loading.
Sourcefn unload_plugin(&mut self, _plugin: &Plugin<'a, O, I>) -> ManagerResult<()>
fn unload_plugin(&mut self, _plugin: &Plugin<'a, O, I>) -> ManagerResult<()>
Unloads a plugin from the execution environment.
This method is called when a plugin is being unloaded. It should clean up any resources associated with the plugin.
Default implementation does nothing and returns Ok(()).
§Parameters
plugin
- Reference to the plugin being unloaded
§Returns
Returns ManagerResult<()>
indicating success or failure of plugin unloading.