pub trait Plugin {
type State: 'static;
// Required method
fn name(&self) -> &'static str;
// Provided methods
fn init(&self) -> Self::State
where Self::State: Default { ... }
fn on_before_render<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>) { ... }
fn on_render<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>) { ... }
fn on_shutdown<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>) { ... }
}Expand description
A plugin: a named, self-contained extension with typed state.
Implementors decide what happens at each lifecycle point. All hooks have default no-op implementations, so a plugin only overrides the ones it cares about.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn init(&self) -> Self::State
fn init(&self) -> Self::State
Called once when the plugin is registered, returning its initial state.
The default returns () (stateless).
Sourcefn on_before_render<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>)
fn on_before_render<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>)
Called before the app builds its tree for a render. Use this to seed
data, reset per-render accumulators, etc. A is the app-wide shared
state type (usually () unless the host registered app state).
Sourcefn on_render<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>)
fn on_render<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>)
Called after the app has built its tree for a render. Use this for post-processing, analytics, or inspecting the produced tree.
Sourcefn on_shutdown<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>)
fn on_shutdown<A: 'static>(&self, _ctx: &PluginCtx<'_, Self::State, A>)
Called once when the app shuts down. Use this to flush logs, persist state, or release native resources.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".