Skip to main content

Module plugin

Module plugin 

Source
Expand description

The Plugin trait — umbral’s only extension mechanism.

Auth, sessions, admin, tasks, REST, and OpenAPI are all plugins; so is every third-party crate that ships models, routes, or commands. This module defines the contract, the AppContext plugins receive, and the BuildError variants topological-sort issues surface as.

See docs/specs/02-plugin-contract.md for the eventual target shape; this file ships the M7 v1 subset (no middleware, no commands, no inventory auto-registration).

§The trait

use umbral::prelude::*;

pub struct BlogPlugin;

impl Plugin for BlogPlugin {
    fn name(&self) -> &'static str { "blog" }

    fn dependencies(&self) -> &'static [&'static str] { &["auth"] }

    fn models(&self) -> Vec<umbral::migrate::ModelMeta> {
        vec![umbral::migrate::ModelMeta::for_::<Post>()]
    }

    fn routes(&self) -> Router {
        Router::new().route("/posts", get(list))
    }
}

AppBuilder::plugin(BlogPlugin) registers it; App::build() topologically sorts the registered plugins, walks every plugin’s routes / models / system_checks, and fires on_ready in dependency order.

Structs§

ApiEndpoint
One callable endpoint a plugin advertises for service discovery. Returned from Plugin::api_endpoints and collected at App::build() into crate::migrate::registered_api_endpoints.
AppContext
The handle plugins receive in on_ready.
StaticDir
One on-disk source directory a plugin contributes to the unified static pipeline. Returned from Plugin::static_dirs.
StaticFile
One static file a plugin ships baked into its binary. Returned from Plugin::static_files.

Traits§

Plugin
The contract every umbral extension implements.

Functions§

block_on_ready
Run an async future to completion from inside a synchronous Plugin::on_ready implementation.

Type Aliases§

PluginError
Errors a plugin’s on_ready can return. Boxed under BuildError::PluginOnReady so the build phase surfaces them with the plugin name attached.