Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin:
    Send
    + Sync
    + Debug {
    // Required methods
    fn name(&self) -> &'static str;
    fn apply<'life0, 'async_trait>(
        &'life0 self,
        ctx: Arc<Context>,
    ) -> Pin<Box<dyn Future<Output = FrameworkResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn on_load<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = FrameworkResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_unload<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = FrameworkResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

插件特性,定义了插件的基本行为。

插件应该能够响应会话事件,并拥有一个唯一的名称。

Required Methods§

Source

fn name(&self) -> &'static str

返回插件的唯一名称。

Source

fn apply<'life0, 'async_trait>( &'life0 self, ctx: Arc<Context>, ) -> Pin<Box<dyn Future<Output = FrameworkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

当新的会话(通常由传入事件触发)创建时调用此方法。

插件可以检查会话内容并决定是否以及如何响应该事件。

§参数
  • session - 一个 Arc<Session>,代表当前的事件上下文。
§返回

如果处理成功,返回 Ok(()),否则返回一个错误。

Provided Methods§

Source

fn on_load<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = FrameworkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_unload<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = FrameworkResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§