Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn info(&self) -> PluginInfo;

    // Provided methods
    fn on_request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _config: &'life1 Value,
        _head: &'life2 mut Parts,
        _ctx: &'life3 mut dyn PluginContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_request_body<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _config: &'life1 Value,
        _body: &'life2 mut Option<Bytes>,
        _ctx: &'life3 mut dyn PluginContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_response<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _config: &'life1 Value,
        _head: &'life2 mut Parts,
        _ctx: &'life3 mut dyn PluginContext,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_response_body(
        &self,
        _config: &Value,
        _body: &mut Option<Bytes>,
        _ctx: &mut dyn PluginContext,
    ) -> Result<(), PluginError> { ... }
    fn on_logging<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _: &'life1 Value,
        _: &'life2 mut dyn PluginContext,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

插件接口 trait

插件开发者实现此 trait,宿主侧通过 plugin-manager 调用。 上下文参数使用 &mut dyn PluginContext,宿主侧和 WASM 侧分别有不同实现。

Required Methods§

Source

fn name(&self) -> &str

插件名称

Source

fn info(&self) -> PluginInfo

插件信息

Provided Methods§

Source

fn on_request<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _config: &'life1 Value, _head: &'life2 mut Parts, _ctx: &'life3 mut dyn PluginContext, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

请求阶段,可改写头部

Source

fn on_request_body<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _config: &'life1 Value, _body: &'life2 mut Option<Bytes>, _ctx: &'life3 mut dyn PluginContext, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

请求体阶段,可改写请求体

Source

fn on_response<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _config: &'life1 Value, _head: &'life2 mut Parts, _ctx: &'life3 mut dyn PluginContext, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

响应阶段,可改写头部

Source

fn on_response_body( &self, _config: &Value, _body: &mut Option<Bytes>, _ctx: &mut dyn PluginContext, ) -> Result<(), PluginError>

响应体阶段,可改写响应体(同步)

Source

fn on_logging<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _: &'life1 Value, _: &'life2 mut dyn PluginContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

日志阶段

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§