Skip to main content

Loader

Trait Loader 

Source
pub trait Loader:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &'static str;
    fn discover<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 LoadContext,
    ) -> Pin<Box<dyn Future<Output = Result<ComponentSet>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

加载器 trait

定义了组件的发现接口。每个加载器实现 discover 方法返回一组候选组件。

§要求

  • 必须是线程安全的(Send + Sync
  • 必须具有 'static 生命周期

§示例

use async_trait::async_trait;
use puniyu_loader::{Loader, LoadContext, ComponentSet};

struct MyLoader;

#[async_trait]
impl Loader for MyLoader {
    fn name(&self) -> &'static str {
        "my_loader"
    }

    async fn discover(&self, _ctx: &LoadContext) -> puniyu_error::Result<ComponentSet> {
        Ok(ComponentSet {
            adapters: vec![],
            plugins: vec![],
        })
    }
}

Required Methods§

Source

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

获取加载器名称

Source

fn discover<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 LoadContext, ) -> Pin<Box<dyn Future<Output = Result<ComponentSet>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行组件发现

根据给定的上下文发现可用的适配器和插件。

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§