pub trait Plugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn handle(&self, ctx: CommandContext) -> BoxFuture<'_, Result<PluginResult>>;
// Provided methods
fn version(&self) -> &str { ... }
fn api_version(&self) -> u32 { ... }
fn min_protocol(&self) -> &str { ... }
fn commands(&self) -> Vec<CommandInfo> { ... }
fn on_user_join(&self, _user: &str) { ... }
fn on_user_leave(&self, _user: &str) { ... }
}Expand description
A plugin that handles one or more / commands and/or reacts to room
lifecycle events.
Implement this trait and register it with the broker’s plugin registry to
add custom commands to a room. The broker dispatches matching
Message::Command messages to the plugin’s handle
method, and calls on_user_join /
on_user_leave when users enter or leave.
Only name and handle are required.
All other methods have no-op / empty-vec defaults so that adding new
lifecycle hooks in future releases does not break existing plugins.
Required Methods§
Sourcefn handle(&self, ctx: CommandContext) -> BoxFuture<'_, Result<PluginResult>>
fn handle(&self, ctx: CommandContext) -> BoxFuture<'_, Result<PluginResult>>
Handle an invocation of one of this plugin’s commands.
Returns a boxed future for dyn compatibility (required because the
registry stores Box<dyn Plugin>).
Provided Methods§
Sourcefn version(&self) -> &str
fn version(&self) -> &str
Semantic version of this plugin (e.g. "1.0.0").
Used for diagnostics and /info output. Defaults to "0.0.0" for
plugins that do not track their own version.
Sourcefn api_version(&self) -> u32
fn api_version(&self) -> u32
Plugin API version this plugin was written against.
The broker rejects plugins whose api_version() exceeds the current
PLUGIN_API_VERSION. Bump this constant when the Plugin trait
gains new required methods or changes existing method signatures.
Defaults to 1 (the initial API revision).
Sourcefn min_protocol(&self) -> &str
fn min_protocol(&self) -> &str
Minimum room-protocol crate version this plugin requires, as a
semver string (e.g. "3.1.0").
The broker rejects plugins whose min_protocol() is newer than the
running room-protocol version. Defaults to "0.0.0" (compatible
with any protocol version).
Sourcefn commands(&self) -> Vec<CommandInfo>
fn commands(&self) -> Vec<CommandInfo>
Commands this plugin handles. Each entry drives /help output
and TUI autocomplete.
Defaults to an empty vec for plugins that only use lifecycle hooks and do not register any commands.
Sourcefn on_user_join(&self, _user: &str)
fn on_user_join(&self, _user: &str)
Called after a user joins the room. The default is a no-op.
Invoked synchronously during the join broadcast path. Implementations must not block — spawn a task if async work is needed.
Sourcefn on_user_leave(&self, _user: &str)
fn on_user_leave(&self, _user: &str)
Called after a user leaves the room. The default is a no-op.
Invoked synchronously during the leave broadcast path. Implementations must not block — spawn a task if async work is needed.