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 version(&self) -> Cow<'static, str> { ... }
fn services(&self) -> Vec<ServiceDesc> { ... }
fn on_init(&self, _ctx: &PluginContext) { ... }
fn on_start(&self) { ... }
fn on_stop(&self) { ... }
}Required Methods§
Provided Methods§
Sourcefn routes(&self) -> Vec<Cow<'static, str>>
fn routes(&self) -> Vec<Cow<'static, str>>
订阅的 type 集合:广播 type(如业务常量 “eTick.”)、 自身的寻址 type(e_req_type(本名)/e_to_type(本名))。 宿主 start() 装配 forwarder → 邮箱 → on_mail。
Sourcefn mailbox_cap(&self) -> usize
fn mailbox_cap(&self) -> usize
邮箱容量覆写(D5:按插件可小可大,默认 MAILBOX_CAP)。
Sourcefn version(&self) -> Cow<'static, str>
fn version(&self) -> Cow<'static, str>
插件版本(约定填 crate 版本)。默认空串 = 「未知版本」。
⚠ 陷阱(审核 F6):默认实现无法用 env!(CARGO_PKG_VERSION)
—— 该宏在 ek-core 定义处展开,填出的是 ek-core 的版本。
插件侧必须显式覆写:
ⓘ
fn version(&self) -> Cow<'static, str> {
Cow::Borrowed(env!("CARGO_PKG_VERSION"))
}Sourcefn services(&self) -> Vec<ServiceDesc>
fn services(&self) -> Vec<ServiceDesc>
服务目录自报(纯声明):只在 add_plugin 时被宿主读取一次抽 id 织入路由索引;
之后 ctx.services_of/find_service/ask_service 需要明细时由宿主现场调用本方法取。
铁律(审核 F8):本方法必须纯/静态/无锁/不阻塞 —— 它会在宿主管理线程上被 与插件 worker 并发调用;违反此纪律后果自负。
目录改版铁律(执行期 DV4 发现):插件目录随配置/状态变化时,必须 先更新本方法返回的内容,再 ctx.publish_services(…) 申报 —— 宿主现场取,先申报后换内容会造成 live 细节与索引脱节。
Sourcefn on_init(&self, _ctx: &PluginContext)
fn on_init(&self, _ctx: &PluginContext)
可选:启动前纯接线(缓存 ctx、读配置)。禁止在此 put/注册 handler(规范)。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".