pub struct PluginConfig {
pub data: Value,
pub init_params: Option<Value>,
pub worker_threads: Option<usize>,
pub log_level: String,
pub max_concurrent_ops: usize,
pub shutdown_timeout_ms: u64,
}Expand description
Plugin configuration passed during initialization
Fields§
§data: ValuePlugin-specific configuration data
General runtime configuration such as database URLs, API keys, feature flags, etc. Accessible throughout the plugin’s lifetime.
init_params: Option<Value>Initialization parameters
Structured data passed to the plugin during initialization.
Intended for one-time setup parameters that are only needed during on_start().
Provides better separation from runtime configuration in data.
worker_threads: Option<usize>Number of async worker threads (default: number of CPU cores)
log_level: StringInitial log level
max_concurrent_ops: usizeMaximum concurrent async operations
shutdown_timeout_ms: u64Shutdown timeout in milliseconds
Implementations§
Source§impl PluginConfig
impl PluginConfig
Sourcepub fn get<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>
pub fn get<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>
Get a typed value from the configuration data
Sourcepub fn set<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error>
pub fn set<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error>
Set a value in the configuration data
Sourcepub fn get_init_param<T: for<'de> Deserialize<'de>>(
&self,
key: &str,
) -> Option<T>
pub fn get_init_param<T: for<'de> Deserialize<'de>>( &self, key: &str, ) -> Option<T>
Get a typed value from initialization parameters
Returns None if init_params is not set or the key doesn’t exist.
§Example
#[derive(Deserialize)]
struct DatabaseInit {
migrations_path: String,
seed_data: bool,
}
async fn on_start(&self, ctx: &PluginContext) -> PluginResult<()> {
if let Some(db_init) = ctx.config().get_init_param::<DatabaseInit>("database") {
if db_init.seed_data {
self.seed_database(&db_init.migrations_path).await?;
}
}
Ok(())
}Sourcepub fn init_params_as<T: for<'de> Deserialize<'de>>(&self) -> Option<T>
pub fn init_params_as<T: for<'de> Deserialize<'de>>(&self) -> Option<T>
Get the entire initialization parameters as a typed value
Returns None if init_params is not set.
§Example
#[derive(Deserialize)]
struct InitParams {
setup_mode: String,
enable_features: Vec<String>,
}
async fn on_start(&self, ctx: &PluginContext) -> PluginResult<()> {
if let Some(params) = ctx.config().init_params_as::<InitParams>() {
// Use initialization parameters...
}
Ok(())
}Sourcepub fn set_init_params(&mut self, params: Value)
pub fn set_init_params(&mut self, params: Value)
Trait Implementations§
Source§impl Clone for PluginConfig
impl Clone for PluginConfig
Source§fn clone(&self) -> PluginConfig
fn clone(&self) -> PluginConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more