Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin:
    Any
    + Send
    + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn on_mail(&self, event: &Event);

    // Provided methods
    fn deps(&self) -> &[&str] { ... }
    fn routes(&self) -> Vec<Cow<'static, str>> { ... }
    fn mailbox_cap(&self) -> usize { ... }
    fn on_init(&self, _ctx: &PluginContext) { ... }
    fn on_start(&self) { ... }
    fn on_stop(&self) { ... }
}

Required Methods§

Source

fn name(&self) -> &str

注册键(D2 校验)。

Source

fn on_mail(&self, event: &Event)

★ 唯一业务入口:永远在本插件 worker 线程上串行执行。 广播事件、寻址请求(eReq.<本名>)、定向通知(eTo.<本名>)都从这里进。

Provided Methods§

Source

fn deps(&self) -> &[&str]

D1 显式依赖清单(宿主注册期校验存在性,start 期拓扑排序)。

Source

fn routes(&self) -> Vec<Cow<'static, str>>

订阅的 type 集合:广播 type(如业务常量 “eTick.”)、 自身的寻址 type(e_req_type(本名)/e_to_type(本名))。 宿主 start() 装配 forwarder → 邮箱 → on_mail。

Source

fn mailbox_cap(&self) -> usize

邮箱容量覆写(D5:按插件可小可大,默认 MAILBOX_CAP)。

Source

fn on_init(&self, _ctx: &PluginContext)

可选:启动前纯接线(缓存 ctx、读配置)。禁止在此 put/注册 handler(规范)。

Source

fn on_start(&self)

start() 按依赖拓扑序调用(只一次)。

Source

fn on_stop(&self)

close/remove 按逆依赖序调用;调用后保证不再收到邮件。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§