Expand description
Plugin trait for composable Autumn integrations.
A Plugin encapsulates configuration and wiring for a reusable piece of
infrastructure (durable workflows, live feeds, telemetry exporters, etc.)
that attaches itself to an AppBuilder. Users register plugins with
AppBuilder::plugin or the tuple-taking
AppBuilder::plugins; each plugin’s
build runs exactly once.
§Naming conventions
First-party plugin crates are named autumn-<name>-plugin. Third-party
crates are named autumn-plugin-<name> to keep names unambiguous on
crates.io. Each crate exposes a <Name>Plugin struct at its root with a
::new() constructor and #[must_use] fluent configuration methods.
§Authoring a plugin
use autumn_web::app::AppBuilder;
use autumn_web::plugin::Plugin;
pub struct HelloPlugin {
greeting: String,
}
impl HelloPlugin {
#[must_use]
pub fn new() -> Self {
Self { greeting: "hello".to_owned() }
}
#[must_use]
pub fn greeting(mut self, greeting: impl Into<String>) -> Self {
self.greeting = greeting.into();
self
}
}
impl Plugin for HelloPlugin {
fn build(self, app: AppBuilder) -> AppBuilder {
let greeting = self.greeting;
app.on_startup(move |_state| {
let greeting = greeting.clone();
async move {
tracing::info!(%greeting, "hello plugin started");
Ok(())
}
})
}
}§Duplicate registration
Registering two plugins that share the same Plugin::name is a no-op
after the first: the second call emits a tracing::warn! and returns the
builder unchanged. The default name is std::any::type_name of the
plugin struct, so two different instances of the same type collide by
default – override Plugin::name if a plugin is genuinely designed to
be registered more than once.
Traits§
- Plugin
- A reusable Autumn integration that wires itself into an
AppBuilder. - Plugins
- A bundle of plugins that can be applied to an
AppBuilderin one call.