Skip to main content

Plugin

Trait Plugin 

Source
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§

Source

type State: 'static

The plugin’s shared state type. Defaults to () (stateless plugins).

Required Methods§

Source

fn name(&self) -> &'static str

A stable name, surfaced in devtools/telemetry. Used as a key in the registry; registering two plugins with the same name is an error.

Provided Methods§

Source

fn init(&self) -> Self::State
where Self::State: Default,

Called once when the plugin is registered, returning its initial state. The default returns () (stateless).

Source

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).

Source

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.

Source

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".

Implementors§