PluginRegistry

Struct PluginRegistry 

Source
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

Source

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);
Source

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 plugin
  • plugin - 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))?;
Source

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")?;
Source

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.

Source

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

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

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

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);
Source

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);
Source

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.

Source

pub fn is_registered(&self, id: &str) -> bool

Check if a plugin is registered

§Arguments
  • id - The plugin ID to check
§Returns

true if the plugin is registered, false otherwise.

Source

pub fn plugin_count(&self) -> usize

Get the number of registered plugins

§Returns

The number of currently registered plugins.

Trait Implementations§

Source§

impl Clone for PluginRegistry

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for PluginRegistry

Source§

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

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

impl Default for PluginRegistry

Source§

fn default() -> Self

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

impl ExperimentalApi for PluginRegistry

Source§

const INTRODUCED_IN: &'static str = "0.1.0"

API version this type was introduced in
Source§

const STABILIZATION_TARGET: Option<&'static str>

Expected version when this API will be stabilized
Source§

const KNOWN_LIMITATIONS: &'static [&'static str]

Known limitations or issues with this API

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V