Skip to main content

Mechanic

Trait Mechanic 

Source
pub trait Mechanic {
    // Required method
    fn enabled(&self) -> bool;

    // Provided methods
    fn cmds(&self) -> Vec<Command> { ... }
    fn perms(&self) -> HashSet<String> { ... }
    fn events(&self, _context: &Context) { ... }
    fn register(&self, context: &Context) { ... }
}
Expand description

A trait representing a plugin mechanic that can be enabled or disabled.

Mechanics may optionally expose commands, permission nodes, and event handlers, all registered with the server via Mechanic::register.

Required Methods§

Source

fn enabled(&self) -> bool

Returns true if the module is enabled, false otherwise.

Provided Methods§

Source

fn cmds(&self) -> Vec<Command>

Returns the commands provided by this mechanic.

Each [Command] returned here will be registered with the server when Mechanic::register is called. Returns an empty vec by default.

Source

fn perms(&self) -> HashSet<String>

Returns the permission nodes required by this mechanic.

Permissions are paired with commands by index when registering. If there are fewer permissions than commands, remaining commands are registered without a permission requirement. Returns an empty set by default.

Source

fn events(&self, _context: &Context)

Registers event handlers for this mechanic.

Override this to call [Context::register_event_handler] for each event this mechanic handles. No-op by default.

Source

fn register(&self, context: &Context)

Registers this mechanic’s event handlers and commands with the server.

Calls Mechanic::events, then registers each command from Mechanic::cmds paired with its corresponding permission from Mechanic::perms by index. Commands without a paired permission use an empty permission string.

Implementors§