Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn boot<'life0, 'async_trait>(
        &'life0 mut self,
        ctx: PluginContext,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn rpc_methods(&self) -> Vec<RpcMethodDef> { ... }
}
Expand description

Lifecycle of a Folk plugin.

At server startup, plugins are booted in registration order. At shutdown, they are stopped in reverse order. A plugin that holds long-running tasks should consider implementing crate::ServerPlugin instead — the wrapper handles the boilerplate of spawning, holding handles, and joining.

Required Methods§

Source

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

Stable plugin name. Conventionally lowercase, single-word: "http", "jobs", "metrics". Used for log scoping, health/metric labels, and config-section routing in custom builds.

Source

fn boot<'life0, 'async_trait>( &'life0 mut self, ctx: PluginContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called once at server startup. Register RPC methods, health checks, and metrics via ctx, then spawn background tasks. Returning Err is fatal: the server aborts startup.

Source

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called during graceful shutdown. Returning Err is logged but does not abort shutdown of other plugins.

Provided Methods§

Source

fn rpc_methods(&self) -> Vec<RpcMethodDef>

Optional: the RPC methods this plugin exposes. Used for advertising (e.g., folk admin list-methods). Default is empty.

Implementors§