Skip to main content

PluginManager

Struct PluginManager 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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"
Source

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.

Source

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.

Source

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.

Source

pub fn get_plugin(&self, name: &str) -> Option<&Plugins>

Gets a plugin as a trait object based on its type

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn get_plugins_by_type_connection( &self, ) -> Vec<(&String, &Box<dyn PluginConnection>)>

Gets all Base plugins with their trait objects

Source

pub fn get_plugins_by_type_inventory( &self, ) -> Vec<(&String, &Box<dyn PluginInventory>)>

Gets all Inventory plugins with their trait objects

Source

pub fn get_plugins_by_type_async_inventory( &self, ) -> Vec<(&String, &Box<dyn AsyncPluginInventory>)>

Gets all async inventory plugins with their trait objects

Source

pub fn get_plugins_by_type_processor( &self, ) -> Vec<(&String, &Box<dyn PluginProcessor>)>

Gets all Processor plugins with their trait objects

Source

pub fn get_plugins_by_type_transform_function( &self, ) -> Vec<(&String, &Box<dyn PluginTransformFunction>)>

Gets all TransformFunction plugins with their trait objects

Source

pub fn deregister_plugin(&mut self, name: &str) -> Option<String>

Deregisters the plugin with the given name.

Source

pub fn deregister_all_plugins(&mut self) -> Vec<String>

Deregisters all plugins.

Source

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.

Source

pub fn get_all_plugin_names(&self) -> Vec<&String>

Gets all the names of the registered plugins.

Source

pub fn get_all_plugin_names_and_groups(&self) -> Vec<(String, String)>

Gets all the names and groups of the registered plugins.

Source

pub fn get_runner_plugin(&self, name: &str) -> Option<&Box<dyn PluginRunner>>

Gets a runner plugin by name, if registered.

Source

pub fn with_path(self, path: &str, group: Option<&str>) -> Result<Self, Error>

Trait Implementations§

Source§

impl Debug for PluginManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PluginManager

Source§

fn default() -> Self

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

impl TaskProcessorResolver for PluginManager

Auto Trait Implementations§

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.