pub trait PluginContext: Send + Sync {
// Required methods
fn get_data(&self, path: &str) -> Option<PluginValue>;
fn set_data(
&self,
path: &str,
value: PluginValue,
) -> Result<(), PluginError>;
fn emit_event(&self, event_type: &str, payload: PluginValue);
fn get_config(&self, path: &str) -> Option<PluginValue>;
fn log(&self, level: LogLevel, message: &str);
fn get_component_property(
&self,
component_id: &str,
property: &str,
) -> Option<PluginValue>;
fn set_component_property(
&self,
component_id: &str,
property: &str,
value: PluginValue,
) -> Result<(), PluginError>;
}Expand description
Context providing API access to plugins at runtime.
This trait is Send + Sync, allowing plugins to use it from background
threads and async tasks. Obtain an Arc<dyn PluginContext> via
PluginRegistrar::context_arc for shared ownership.
§Data Paths
Data paths use dot-separated notation: "data.my_source.items".
Config paths follow the same convention: "app.settings.theme".
§Example
fn read_and_write(ctx: &dyn PluginContext) {
// Read a value
if let Some(PluginValue::Integer(count)) = ctx.get_data("metrics.request_count") {
ctx.log(LogLevel::Info, &format!("Requests: {}", count));
}
// Write a value
ctx.set_data("metrics.last_check", PluginValue::String("now".into())).ok();
// Emit an event for other plugins/components to observe
ctx.emit_event("plugin:refresh", PluginValue::Null);
}Required Methods§
Sourcefn get_data(&self, path: &str) -> Option<PluginValue>
fn get_data(&self, path: &str) -> Option<PluginValue>
Gets data by dot-separated path (e.g. "data.source.field").
Sourcefn set_data(&self, path: &str, value: PluginValue) -> Result<(), PluginError>
fn set_data(&self, path: &str, value: PluginValue) -> Result<(), PluginError>
Sets data at a dot-separated path.
Returns Err if the path is invalid or permission is denied.
Sourcefn emit_event(&self, event_type: &str, payload: PluginValue)
fn emit_event(&self, event_type: &str, payload: PluginValue)
Emits a named event with an arbitrary payload.
Events are delivered asynchronously via the host’s event bus.
Sourcefn get_config(&self, path: &str) -> Option<PluginValue>
fn get_config(&self, path: &str) -> Option<PluginValue>
Gets a configuration value by dot-separated path.
Sourcefn get_component_property(
&self,
component_id: &str,
property: &str,
) -> Option<PluginValue>
fn get_component_property( &self, component_id: &str, property: &str, ) -> Option<PluginValue>
Gets a component property by component ID and property name.
Returns None if the component or property does not exist.
Sourcefn set_component_property(
&self,
component_id: &str,
property: &str,
value: PluginValue,
) -> Result<(), PluginError>
fn set_component_property( &self, component_id: &str, property: &str, value: PluginValue, ) -> Result<(), PluginError>
Sets a component property by component ID and property name.
Returns Err if the component does not exist or the property is
read-only.