Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Configurable {
    // Required methods
    fn init<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 PluginContext,
        handle: Option<Arc<PluginHandle>>,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn query<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 PluginContext,
        query: &'life2 Query,
    ) -> Pin<Box<dyn Future<Output = Result<QueryResponse, PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn execute_action<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 PluginContext,
        action_id: &'life2 str,
        payload: Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided method
    fn interaction_policy(&self) -> PanelInteraction { ... }
}
Expand description

所有插件对象都需实现的核心契约。 服务于插件生命周期管理、查询处理与动作执行。 配置管理能力由 Configurable trait 提供。

Required Methods§

Source

fn init<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 PluginContext, handle: Option<Arc<PluginHandle>>, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

插件初始化钩子。

handle 为宿主注入的平台服务句柄:进程内(内置)插件持有 Some(Arc<PluginHandle>);远端插件进程无宿主句柄(跨进程不可序列化), 收到 None,平台能力经 SDK host() 的 host/* RPC 访问。

Source

fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 PluginContext, query: &'life2 Query, ) -> Pin<Box<dyn Future<Output = Result<QueryResponse, PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn execute_action<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 PluginContext, action_id: &'life2 str, payload: Value, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

执行插件动作。 action_id 为插件在 ListItem.actions / CustomPanel.actions / 面板按键 绑定中声明的动作标识;payload 形状由触发通道决定(插件应两种都兼容):

  • 候选确认通道(搜索栏结果列表 / 行内参数 / 参数面板确认): {"candidate_id": <u64>, "query_text": <str>, "user_args": [<str>]};
  • 面板动作通道(PanelKeyAction::Custom 面板按键绑定):插件自定义自由 JSON, 宿主原样透传。

Provided Methods§

Source

fn interaction_policy(&self) -> PanelInteraction

返回插件当前生效的交互策略(防抖延迟、提交行为等)。 这是一次快速、同步的调用,不涉及 IO 或网络。 默认返回无防抖、Execute 提交的交互策略。

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§