pub struct PluginManager { /* private fields */ }Expand description
Central registry and loader for dynamic plugins.
Holds the loaded plugin instances (plugins), metadata discovered from
plugin manifests (plugin_path), and the underlying dynamic libraries
(libraries) to keep them alive for the lifetime of the manager.
Note: libraries must be retained for as long as any plugin is in use,
otherwise symbol pointers may become invalid.
Implementations§
Source§impl PluginManager
impl PluginManager
pub fn new() -> Self
Sourcepub fn activate_plugins(self) -> Result<PluginManager, Box<dyn Error>>
pub fn activate_plugins(self) -> Result<PluginManager, Box<dyn Error>>
Activate all plugins discovered from metadata and configured paths.
Collects registrations from the plugin manifest and any entries in
plugin_path, then invokes activation for each entry. Returns the
updated PluginManager on success.
Sourcepub fn get_plugin_metadata(&self) -> Metadata
pub fn get_plugin_metadata(&self) -> Metadata
Retrieves the environment variable CARGO_MANIFEST_PATH containing the path to manifest file. The file should contain the plugin metadata in TOML format which contains the following structure:
[package.metadata.plugins]
plugin_a = "/path/to/plugin_a.so"
[package.metadata.plugins.inventory]
inventory_plugin = "/path/to/inventory_plugin.so"Sourcepub fn load_plugin(&self, filename: &str) -> PluginResultPlugins
pub fn load_plugin(&self, filename: &str) -> PluginResultPlugins
Load a dynamic library and invoke its create_plugins factory.
Returns the opened library and the plugins it creates, or an error if the file is missing, cannot be loaded, or the symbol is unavailable.
Sourcepub fn load_plugins_from_directory(
self,
directory: impl AsRef<Path>,
) -> Result<Self, Box<dyn Error>>
pub fn load_plugins_from_directory( self, directory: impl AsRef<Path>, ) -> Result<Self, Box<dyn Error>>
Load all plugin libraries from a directory.
This scans the directory for files matching the current platform’s dynamic-library extension and attempts to load each one.
Sourcepub fn register_plugin(&mut self, plugin: Plugins)
pub fn register_plugin(&mut self, plugin: Plugins)
Insert a plugin into the registry by name.
Panics if a plugin with the same name is already registered.
Sourcepub fn get_plugin(&self, name: &str) -> Option<&Plugins>
pub fn get_plugin(&self, name: &str) -> Option<&Plugins>
Gets a plugin as a trait object based on its type
Sourcepub fn get_connection_plugin(
&self,
name: &str,
) -> Option<&Box<dyn PluginConnection>>
pub fn get_connection_plugin( &self, name: &str, ) -> Option<&Box<dyn PluginConnection>>
Gets an inventory plugin, returns None if the plugin is not a Base variant
Sourcepub fn get_inventory_plugin(
&self,
name: &str,
) -> Option<&Box<dyn PluginInventory>>
pub fn get_inventory_plugin( &self, name: &str, ) -> Option<&Box<dyn PluginInventory>>
Gets an inventory plugin, returns None if the plugin is not an Inventory variant
Sourcepub fn get_async_inventory_plugin(
&self,
name: &str,
) -> Option<&Box<dyn AsyncPluginInventory>>
pub fn get_async_inventory_plugin( &self, name: &str, ) -> Option<&Box<dyn AsyncPluginInventory>>
Gets an async inventory plugin, returns None if the plugin is not an AsyncInventory variant
Sourcepub fn get_transform_function_plugin(
&self,
name: &str,
) -> Option<&Box<dyn PluginTransformFunction>>
pub fn get_transform_function_plugin( &self, name: &str, ) -> Option<&Box<dyn PluginTransformFunction>>
Gets a transform function plugin, returns None if the plugin is not a TransformFunction variant
Sourcepub fn get_processor_plugin(
&self,
name: &str,
) -> Option<&Box<dyn PluginProcessor>>
pub fn get_processor_plugin( &self, name: &str, ) -> Option<&Box<dyn PluginProcessor>>
Gets a processor plugin, returns None if the plugin is not a Processor variant
Sourcepub fn get_plugins_by_variant<'a, T>(
&'a self,
mapper: impl Fn(&'a Plugins) -> Option<T>,
) -> Vec<(&'a String, T)>
pub fn get_plugins_by_variant<'a, T>( &'a self, mapper: impl Fn(&'a Plugins) -> Option<T>, ) -> Vec<(&'a String, T)>
Generic method to get plugins by variant type with a mapper function
Sourcepub fn get_plugins_by_type_connection(
&self,
) -> Vec<(&String, &Box<dyn PluginConnection>)>
pub fn get_plugins_by_type_connection( &self, ) -> Vec<(&String, &Box<dyn PluginConnection>)>
Gets all Base plugins with their trait objects
Sourcepub fn get_plugins_by_type_inventory(
&self,
) -> Vec<(&String, &Box<dyn PluginInventory>)>
pub fn get_plugins_by_type_inventory( &self, ) -> Vec<(&String, &Box<dyn PluginInventory>)>
Gets all Inventory plugins with their trait objects
Sourcepub fn get_plugins_by_type_async_inventory(
&self,
) -> Vec<(&String, &Box<dyn AsyncPluginInventory>)>
pub fn get_plugins_by_type_async_inventory( &self, ) -> Vec<(&String, &Box<dyn AsyncPluginInventory>)>
Gets all async inventory plugins with their trait objects
Sourcepub fn get_plugins_by_type_processor(
&self,
) -> Vec<(&String, &Box<dyn PluginProcessor>)>
pub fn get_plugins_by_type_processor( &self, ) -> Vec<(&String, &Box<dyn PluginProcessor>)>
Gets all Processor plugins with their trait objects
Sourcepub fn get_plugins_by_type_transform_function(
&self,
) -> Vec<(&String, &Box<dyn PluginTransformFunction>)>
pub fn get_plugins_by_type_transform_function( &self, ) -> Vec<(&String, &Box<dyn PluginTransformFunction>)>
Gets all TransformFunction plugins with their trait objects
Sourcepub fn deregister_plugin(&mut self, name: &str) -> Option<String>
pub fn deregister_plugin(&mut self, name: &str) -> Option<String>
Deregisters the plugin with the given name.
Sourcepub fn deregister_all_plugins(&mut self) -> Vec<String>
pub fn deregister_all_plugins(&mut self) -> Vec<String>
Deregisters all plugins.
Sourcepub fn merge(&mut self, other: PluginManager)
pub fn merge(&mut self, other: PluginManager)
Merge another plugin manager into this one, overriding plugins with the same name.
Plugin libraries and deferred plugin path entries are retained so any loaded dynamic plugins remain valid after the merge. When a plugin name collision occurs, the incoming plugin replaces the existing registration.
Sourcepub fn get_all_plugin_names(&self) -> Vec<&String>
pub fn get_all_plugin_names(&self) -> Vec<&String>
Gets all the names of the registered plugins.
Sourcepub fn get_all_plugin_names_and_groups(&self) -> Vec<(String, String)>
pub fn get_all_plugin_names_and_groups(&self) -> Vec<(String, String)>
Gets all the names and groups of the registered plugins.
Sourcepub fn get_runner_plugin(&self, name: &str) -> Option<&Box<dyn PluginRunner>>
pub fn get_runner_plugin(&self, name: &str) -> Option<&Box<dyn PluginRunner>>
Gets a runner plugin by name, if registered.