Skip to main content

PluginConfig

Struct PluginConfig 

Source
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: Value

Plugin-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: String

Initial log level

§max_concurrent_ops: usize

Maximum concurrent async operations

§shutdown_timeout_ms: u64

Shutdown timeout in milliseconds

Implementations§

Source§

impl PluginConfig

Source

pub fn new() -> Self

Create a new empty configuration

Source

pub fn from_json(bytes: &[u8]) -> Result<Self, Error>

Create configuration from JSON bytes

Source

pub fn get<T: for<'de> Deserialize<'de>>(&self, key: &str) -> Option<T>

Get a typed value from the configuration data

Source

pub fn set<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error>

Set a value in the configuration data

Source

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(())
}
Source

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(())
}
Source

pub fn set_init_params(&mut self, params: Value)

Set initialization parameters

This is typically called by the host application before initializing the plugin.

§Example
let mut config = PluginConfig::default();
config.set_init_params(serde_json::json!({
    "setup_mode": "development",
    "seed_data": true
}));

Trait Implementations§

Source§

impl Clone for PluginConfig

Source§

fn clone(&self) -> PluginConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PluginConfig

Source§

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

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

impl Default for PluginConfig

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for PluginConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for PluginConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,