Skip to main content

PluginRegistry

Struct PluginRegistry 

Source
pub struct PluginRegistry { /* private fields */ }
Expand description

Thread-safe registry for custom forecast models and anomaly detectors.

Plugins register factory functions keyed by name. The factories are called at runtime to create model/detector instances with user-supplied config.

All registration and lookup operations are lock-free (DashMap-backed) and safe under concurrent access. Registration uses atomic entry-based insertion to prevent TOCTOU races.

Implementations§

Source§

impl PluginRegistry

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn register_model( &self, name: impl Into<String>, factory: ModelFactory, ) -> Result<(), PluginError>

Register a custom forecast model factory.

Returns an error if the name is invalid or a model with the same name is already registered. Uses atomic entry insertion to prevent TOCTOU races.

Source

pub fn register_model_with_info( &self, info: PluginInfo, factory: ModelFactory, ) -> Result<(), PluginError>

Register a custom forecast model factory with explicit metadata.

Source

pub fn replace_model( &self, name: impl Into<String>, factory: ModelFactory, ) -> Result<Option<PluginInfo>, PluginError>

Atomically replace a model factory. Inserts if not present.

Returns the previous PluginInfo if there was an existing registration.

Source

pub fn replace_model_with_info( &self, info: PluginInfo, factory: ModelFactory, ) -> Result<Option<PluginInfo>, PluginError>

Atomically replace a model factory with explicit metadata.

Source

pub fn create_model( &self, name: &str, config: &Value, ) -> Result<Box<dyn ForecastModel>, PluginError>

Create a forecast model instance by plugin name.

Source

pub fn create_model_default( &self, name: &str, ) -> Result<Box<dyn ForecastModel>, PluginError>

Create a forecast model with default (null) configuration.

Source

pub fn try_create_model( &self, name: &str, config: &Value, ) -> Option<Result<Box<dyn ForecastModel>, PluginError>>

Try to create a forecast model if the plugin is registered.

Returns None if no plugin with the given name exists. Returns Some(Err(...)) if the plugin exists but the factory fails. Single DashMap lookup — no TOCTOU.

Source

pub fn try_create_model_default( &self, name: &str, ) -> Option<Result<Box<dyn ForecastModel>, PluginError>>

Try to create a forecast model with default config (single lookup).

Source

pub fn has_model(&self, name: &str) -> bool

Check if a model plugin is registered.

Source

pub fn model_info(&self, name: &str) -> Option<PluginInfo>

Get metadata for a registered model plugin.

Source

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

List all registered model plugin names (sorted).

Source

pub fn list_model_infos(&self) -> Vec<PluginInfo>

List all registered model plugins with their metadata (sorted by name).

Source

pub fn unregister_model(&self, name: &str) -> Option<PluginInfo>

Unregister a model plugin. Returns the PluginInfo if it existed.

Source

pub fn model_count(&self) -> usize

Number of registered model plugins.

Source

pub fn register_detector( &self, name: impl Into<String>, factory: DetectorFactory, ) -> Result<(), PluginError>

Register a custom anomaly detector factory.

Returns an error if the name is invalid or a detector with the same name is already registered. Uses atomic entry insertion to prevent TOCTOU races.

Source

pub fn register_detector_with_info( &self, info: PluginInfo, factory: DetectorFactory, ) -> Result<(), PluginError>

Register a custom anomaly detector factory with explicit metadata.

Source

pub fn replace_detector( &self, name: impl Into<String>, factory: DetectorFactory, ) -> Result<Option<PluginInfo>, PluginError>

Atomically replace a detector factory. Inserts if not present.

Returns the previous PluginInfo if there was an existing registration.

Source

pub fn replace_detector_with_info( &self, info: PluginInfo, factory: DetectorFactory, ) -> Result<Option<PluginInfo>, PluginError>

Atomically replace a detector factory with explicit metadata.

Source

pub fn create_detector( &self, name: &str, config: &Value, ) -> Result<Box<dyn AnomalyDetector>, PluginError>

Create an anomaly detector instance by plugin name.

Source

pub fn create_detector_default( &self, name: &str, ) -> Result<Box<dyn AnomalyDetector>, PluginError>

Create an anomaly detector with default (null) configuration.

Source

pub fn try_create_detector( &self, name: &str, config: &Value, ) -> Option<Result<Box<dyn AnomalyDetector>, PluginError>>

Try to create an anomaly detector if the plugin is registered.

Returns None if no plugin with the given name exists. Returns Some(Err(...)) if the plugin exists but the factory fails. Single DashMap lookup — no TOCTOU.

Source

pub fn try_create_detector_default( &self, name: &str, ) -> Option<Result<Box<dyn AnomalyDetector>, PluginError>>

Try to create an anomaly detector with default config (single lookup).

Source

pub fn has_detector(&self, name: &str) -> bool

Check if a detector plugin is registered.

Source

pub fn detector_info(&self, name: &str) -> Option<PluginInfo>

Get metadata for a registered detector plugin.

Source

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

List all registered detector plugin names (sorted).

Source

pub fn list_detector_infos(&self) -> Vec<PluginInfo>

List all registered detector plugins with their metadata (sorted by name).

Source

pub fn unregister_detector(&self, name: &str) -> Option<PluginInfo>

Unregister a detector plugin. Returns the PluginInfo if it existed.

Source

pub fn detector_count(&self) -> usize

Number of registered detector plugins.

Source

pub fn total_plugins(&self) -> usize

Total number of registered plugins (models + detectors).

Source

pub fn clear(&self)

Remove all registered models and detectors.

Source

pub fn set_model_allowlist(&self, hashes: impl IntoIterator<Item = String>)

Set the SHA-256 hash allowlist for model plugins.

When the allowlist is non-empty, only plugins whose PluginInfo::sha256_hash is present in the list are accepted. Hashes should be lowercase hex-encoded.

Source

pub fn set_detector_allowlist(&self, hashes: impl IntoIterator<Item = String>)

Set the SHA-256 hash allowlist for detector plugins.

Trait Implementations§

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more