Skip to main content

PluginRegistry

Struct PluginRegistry 

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

Registry for managing plugins

The registry allows you to register, retrieve, and execute plugins.

§Examples

use unistructgen_core::PluginRegistry;

let mut registry = PluginRegistry::new();

// Register plugins
// registry.register(Box::new(my_plugin)).unwrap();

// Get a plugin
// let plugin = registry.get("my_plugin");

Implementations§

Source§

impl PluginRegistry

Source

pub fn new() -> Self

Create a new plugin registry

Source

pub fn register(&mut self, plugin: Box<dyn Plugin>) -> Result<(), PluginError>

Register a plugin

§Errors

Returns an error if a plugin with the same name is already registered.

§Examples
use unistructgen_core::PluginRegistry;

let mut registry = PluginRegistry::new();
// registry.register(Box::new(my_plugin)).unwrap();
Source

pub fn get(&self, name: &str) -> Option<&dyn Plugin>

Get a reference to a plugin by name

§Examples
use unistructgen_core::PluginRegistry;

let registry = PluginRegistry::new();
let plugin = registry.get("my_plugin");
assert!(plugin.is_none());
Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut dyn Plugin>

Get a mutable reference to a plugin by name

Source

pub fn plugin_names(&self) -> Vec<&str>

Get all registered plugin names

§Examples
use unistructgen_core::PluginRegistry;

let registry = PluginRegistry::new();
let names = registry.plugin_names();
assert_eq!(names.len(), 0);
Source

pub fn count(&self) -> usize

Get the number of registered plugins

Source

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

Check if a plugin is registered

Source

pub fn remove(&mut self, name: &str) -> Option<Box<dyn Plugin>>

Remove a plugin by name

§Examples
use unistructgen_core::PluginRegistry;

let mut registry = PluginRegistry::new();
let removed = registry.remove("my_plugin");
assert!(removed.is_none());
Source

pub fn before_parse(&mut self, input: String) -> Result<String, PluginError>

Execute before_parse on all plugins

Plugins are executed in the order they were registered.

Source

pub fn after_parse(&mut self, module: IRModule) -> Result<IRModule, PluginError>

Execute after_parse on all plugins

Plugins are executed in the order they were registered.

Source

pub fn after_generate(&mut self, code: String) -> Result<String, PluginError>

Execute after_generate on all plugins

Plugins are executed in the order they were registered.

Source

pub fn shutdown(&mut self) -> Result<(), PluginError>

Shutdown all plugins

Trait Implementations§

Source§

impl Default for PluginRegistry

Source§

fn default() -> Self

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

impl Drop for PluginRegistry

Source§

fn drop(&mut self)

Executes the destructor for this 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<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.