pub struct PluginRegistry { /* private fields */ }Expand description
Registry for managing plugins
The PluginRegistry provides centralized management of all registered plugins with thread-safe operations, efficient discovery through indexing, and comprehensive lifecycle management.
§Features
- Thread-safe plugin registration and unregistration
- Category-based plugin organization
- Type compatibility indexing for automatic plugin selection
- Metadata caching for fast discovery
- Search functionality by name and description
- Validation and lifecycle management
§Examples
use sklears_core::plugin::{PluginRegistry, Plugin, PluginMetadata, PluginCategory};
use sklears_core::error::Result;
use std::any::TypeId;
// Create a registry
let registry = PluginRegistry::new();
// List available plugins
let plugins = registry.list_plugins()?;
println!("Available plugins: {:?}", plugins);
// Search for plugins by category
let algorithms = registry.get_plugins_by_category(&PluginCategory::Algorithm)?;
println!("Algorithm plugins: {:?}", algorithms);
// Find plugins compatible with a specific type
let compatible = registry.get_compatible_plugins(TypeId::of::<f64>())?;
println!("f64-compatible plugins: {:?}", compatible);Implementations§
Source§impl PluginRegistry
impl PluginRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new plugin registry
Initializes an empty registry with all necessary internal data structures for efficient plugin management and discovery.
§Examples
use sklears_core::plugin::PluginRegistry;
let registry = PluginRegistry::new();
assert_eq!(registry.list_plugins().unwrap().len(), 0);Sourcepub fn register(&self, id: &str, plugin: Box<dyn Plugin>) -> Result<()>
pub fn register(&self, id: &str, plugin: Box<dyn Plugin>) -> Result<()>
Register a plugin in the registry
This method registers a new plugin with the given ID, validates its metadata, and updates all internal indices for efficient discovery.
§Arguments
id- Unique identifier for the pluginplugin- The plugin instance to register
§Returns
Ok(()) on successful registration, or an error if validation fails or the plugin cannot be registered.
§Examples
use sklears_core::plugin::{PluginRegistry, Plugin};
let registry = PluginRegistry::new();
// registry.register("my_plugin", Box::new(my_plugin_instance))?;Sourcepub fn unregister(&self, id: &str) -> Result<()>
pub fn unregister(&self, id: &str) -> Result<()>
Unregister a plugin from the registry
This method removes a plugin from the registry, cleans up its resources, and updates all internal indices.
§Arguments
id- The ID of the plugin to unregister
§Returns
Ok(()) on successful unregistration, or an error if the operation fails.
§Examples
use sklears_core::plugin::PluginRegistry;
let registry = PluginRegistry::new();
// First register a plugin...
// registry.register("my_plugin", Box::new(my_plugin_instance))?;
// Then unregister it
registry.unregister("my_plugin")?;Sourcepub fn get_plugin(&self, id: &str) -> Result<Arc<RwLock<Box<dyn Plugin>>>>
pub fn get_plugin(&self, id: &str) -> Result<Arc<RwLock<Box<dyn Plugin>>>>
Get a reference to a plugin by ID
Note: This is a simplified implementation. In practice, you’d want to return a proper reference or handle that manages plugin lifetime.
§Arguments
id- The ID of the plugin to retrieve
§Returns
An error in this simplified implementation, as proper plugin access requires careful lifetime management.
Sourcepub fn list_plugins(&self) -> Result<Vec<String>>
pub fn list_plugins(&self) -> Result<Vec<String>>
List all registered plugin IDs
Returns a vector of all plugin IDs currently registered in the system.
§Returns
A vector of plugin IDs, or an error if the registry cannot be accessed.
§Examples
use sklears_core::plugin::PluginRegistry;
let registry = PluginRegistry::new();
let plugins = registry.list_plugins().unwrap();
assert!(plugins.is_empty()); // No plugins registered yetSourcepub fn get_plugins_by_category(
&self,
category: &PluginCategory,
) -> Result<Vec<String>>
pub fn get_plugins_by_category( &self, category: &PluginCategory, ) -> Result<Vec<String>>
Get all plugins in a specific category
Returns all plugin IDs that belong to the specified category.
§Arguments
category- The category to search for
§Returns
A vector of plugin IDs in the category, or an error if the index cannot be accessed.
§Examples
use sklears_core::plugin::{PluginRegistry, PluginCategory};
let registry = PluginRegistry::new();
let algorithms = registry.get_plugins_by_category(&PluginCategory::Algorithm).unwrap();
assert!(algorithms.is_empty()); // No plugins registered yetSourcepub fn get_compatible_plugins(&self, type_id: TypeId) -> Result<Vec<String>>
pub fn get_compatible_plugins(&self, type_id: TypeId) -> Result<Vec<String>>
Get plugins compatible with a specific data type
Returns all plugin IDs that declare compatibility with the given TypeId.
§Arguments
type_id- The TypeId to check compatibility for
§Returns
A vector of compatible plugin IDs, or an error if the index cannot be accessed.
§Examples
use sklears_core::plugin::PluginRegistry;
use std::any::TypeId;
let registry = PluginRegistry::new();
let compatible = registry.get_compatible_plugins(TypeId::of::<f64>()).unwrap();
assert!(compatible.is_empty()); // No plugins registered yetSourcepub fn get_metadata(&self, id: &str) -> Result<PluginMetadata>
pub fn get_metadata(&self, id: &str) -> Result<PluginMetadata>
Get metadata for a specific plugin
Returns the cached metadata for the plugin with the given ID.
§Arguments
id- The ID of the plugin
§Returns
The plugin’s metadata, or an error if the plugin is not found.
§Examples
use sklears_core::plugin::PluginRegistry;
let registry = PluginRegistry::new();
// First register a plugin...
// registry.register("my_plugin", Box::new(my_plugin_instance))?;
// Then get its metadata
let metadata = registry.get_metadata("my_plugin")?;
println!("Plugin: {} v{}", metadata.name, metadata.version);Sourcepub fn search_plugins(&self, query: &str) -> Result<Vec<String>>
pub fn search_plugins(&self, query: &str) -> Result<Vec<String>>
Search plugins by name or description
Performs a case-insensitive search through plugin names and descriptions for the given query string.
§Arguments
query- The search query string
§Returns
A vector of plugin IDs that match the search query, or an error if the search cannot be performed.
§Examples
use sklears_core::plugin::PluginRegistry;
let registry = PluginRegistry::new();
// Register some plugins first...
// Search for plugins
let matches = registry.search_plugins("regression")?;
println!("Found regression plugins: {:?}", matches);Sourcepub fn get_statistics(&self) -> Result<HashMap<String, usize>>
pub fn get_statistics(&self) -> Result<HashMap<String, usize>>
Get registry statistics
Returns information about the current state of the registry.
§Returns
A HashMap with statistics about the registry.
Sourcepub fn is_registered(&self, id: &str) -> bool
pub fn is_registered(&self, id: &str) -> bool
Sourcepub fn plugin_count(&self) -> usize
pub fn plugin_count(&self) -> usize
Trait Implementations§
Source§impl Clone for PluginRegistry
impl Clone for PluginRegistry
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Clone the registry (creates a new registry with the same structure but empty)
Note: This doesn’t clone the actual plugins, just the registry structure. This is because plugins contain trait objects that can’t be easily cloned.
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PluginRegistry
impl Debug for PluginRegistry
Source§impl Default for PluginRegistry
impl Default for PluginRegistry
Source§impl ExperimentalApi for PluginRegistry
impl ExperimentalApi for PluginRegistry
Source§const INTRODUCED_IN: &'static str = "0.1.0"
const INTRODUCED_IN: &'static str = "0.1.0"
Source§const STABILIZATION_TARGET: Option<&'static str>
const STABILIZATION_TARGET: Option<&'static str>
Source§const KNOWN_LIMITATIONS: &'static [&'static str]
const KNOWN_LIMITATIONS: &'static [&'static str]
Auto Trait Implementations§
impl Freeze for PluginRegistry
impl RefUnwindSafe for PluginRegistry
impl Send for PluginRegistry
impl Sync for PluginRegistry
impl Unpin for PluginRegistry
impl UnsafeUnpin for PluginRegistry
impl UnwindSafe for PluginRegistry
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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