Skip to main content

Plugin

Derive Macro Plugin 

Source
#[derive(Plugin)]
{
    // Attributes available to this derive:
    #[plugin]
}
Expand description

从结构体上的 #[plugin(depends(A, B))] 生成 [plugctx::Plugin] 实现。

  • dependencies():返回声明类型的 TypeId 列表(无 depends 则为空)。
  • build():委托到用户固有方法 fn on_build(&self, ctx: &mut Context) -> Result<(), Error>

§示例

use plugctx_derive::Plugin;

#[derive(Plugin)]
#[plugin(depends(Logger))]
struct MyPlugin;

impl MyPlugin {
    fn on_build(&self, ctx: &mut plugctx::Context) -> Result<(), plugctx::Error> {
        let _ = ctx.get::<Logger>();
        Ok(())
    }
}