pub trait PluginFactory:
Default
+ Plugin
+ Sized {
// Provided methods
fn create(config: &PluginConfig) -> PluginResult<Self> { ... }
fn create_configured(_config: &PluginConfig) -> PluginResult<Self> { ... }
}Expand description
Factory trait for creating plugins with optional configuration.
The framework calls create() which handles the null-config case
automatically by falling back to Default::default().
Plugin authors only need to override create_configured() if they
want to use config.data for initialization.
§Example
ⓘ
use rustbridge_core::prelude::*;
struct MyPlugin {
cache_size: usize,
}
impl Default for MyPlugin {
fn default() -> Self {
Self { cache_size: 100 }
}
}
impl PluginFactory for MyPlugin {
fn create_configured(config: &PluginConfig) -> PluginResult<Self> {
let size = config.get::<usize>("cache_size").unwrap_or(100);
Ok(Self { cache_size: size })
}
}Provided Methods§
Sourcefn create(config: &PluginConfig) -> PluginResult<Self>
fn create(config: &PluginConfig) -> PluginResult<Self>
Create a plugin instance. Called by the framework.
Default implementation: uses Default when config.data is null,
otherwise calls create_configured().
Sourcefn create_configured(_config: &PluginConfig) -> PluginResult<Self>
fn create_configured(_config: &PluginConfig) -> PluginResult<Self>
Create a plugin with non-null config.data.
Override this to parse and use configuration data.
Default implementation ignores config and uses Default.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.