pub struct PluginLoader { /* private fields */ }Expand description
Plugin loader for dynamic library loading
The PluginLoader provides functionality to load plugins from dynamic libraries at runtime. It manages the lifecycle of loaded libraries and integrates with the plugin registry for automatic plugin registration.
§Features
- Dynamic library loading from files or directories
- Automatic plugin discovery and registration
- Proper library lifecycle management
- Cross-platform support (Windows DLL, Linux SO, macOS dylib)
- Error handling and validation
§Examples
use sklears_core::plugin::{PluginLoader, PluginRegistry};
use std::sync::Arc;
let registry = Arc::new(PluginRegistry::new());
let mut loader = PluginLoader::new(registry.clone());
// Load a single plugin
loader.load_from_library("./plugins/my_plugin.so", "my_plugin")?;
// Load all plugins from a directory
let loaded = loader.load_from_directory("./plugins/")?;
println!("Loaded {} plugins", loaded.len());§Safety
Dynamic library loading involves unsafe operations. The plugin loader takes precautions to ensure safety, but loaded plugins must be trusted and properly implemented.
Implementations§
Source§impl PluginLoader
impl PluginLoader
Sourcepub fn new(registry: Arc<PluginRegistry>) -> Self
pub fn new(registry: Arc<PluginRegistry>) -> Self
Create a new plugin loader
Creates a new plugin loader that will register loaded plugins with the provided registry.
§Arguments
registry- The plugin registry to use for registration
§Examples
use sklears_core::plugin::{PluginLoader, PluginRegistry};
use std::sync::Arc;
let registry = Arc::new(PluginRegistry::new());
let loader = PluginLoader::new(registry);Sourcepub fn registry(&self) -> &Arc<PluginRegistry>
pub fn registry(&self) -> &Arc<PluginRegistry>
Get the plugin registry
Returns a reference to the plugin registry used by this loader.
§Returns
A reference to the plugin registry.
Source§impl PluginLoader
Stub implementations for when dynamic loading is not available
impl PluginLoader
Stub implementations for when dynamic loading is not available
Sourcepub fn load_from_library(
&mut self,
_library_path: &str,
_plugin_id: &str,
) -> Result<()>
pub fn load_from_library( &mut self, _library_path: &str, _plugin_id: &str, ) -> Result<()>
Load a plugin from a dynamic library (stub implementation)
This method is not available when the dynamic_loading feature is disabled.
It will always return an error indicating that dynamic loading is not supported.
Sourcepub fn unload_library(&mut self, _plugin_id: &str) -> Result<()>
pub fn unload_library(&mut self, _plugin_id: &str) -> Result<()>
Unload a plugin library (stub implementation)
This method is not available when the dynamic_loading feature is disabled.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PluginLoader
impl RefUnwindSafe for PluginLoader
impl Send for PluginLoader
impl Sync for PluginLoader
impl Unpin for PluginLoader
impl UnwindSafe for PluginLoader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more