WasmPluginPort

Trait WasmPluginPort 

Source
pub trait WasmPluginPort: Send + Sync {
    // Required methods
    fn discover<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(WasmPluginMeta, Arc<dyn ScrapingService>)>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn load<'life0, 'life1, 'async_trait>(
        &'life0 self,
        path: &'life1 Path,
    ) -> Pin<Box<dyn Future<Output = Result<(WasmPluginMeta, Arc<dyn ScrapingService>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn loaded<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<WasmPluginMeta>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Port: load and manage WASM scraping plugins.

Implementations are responsible for:

  1. Discovering .wasm files in a plugin directory.
  2. Validating that they export the required functions.
  3. Wrapping each plugin as an Arc<dyn ScrapingService> for the service registry.
  4. Hot-reloading when the plugin file changes on disk.

§Example

use stygian_graph::ports::wasm_plugin::WasmPluginPort;

// Implemented by WasmPluginLoader in adapters/wasm_plugin.rs
async fn register_plugins<P: WasmPluginPort>(loader: &P) {
    let plugins = loader.discover().await.unwrap();
    for (meta, svc) in plugins {
        println!("loaded plugin: {}", meta.name);
        let _ = svc;
    }
}

Required Methods§

Source

fn discover<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<(WasmPluginMeta, Arc<dyn ScrapingService>)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Scan the configured plugin directory and load all .wasm files.

Returns (metadata, service) pairs — the service can be registered directly in a ServiceRegistry.

§Example
let plugins = loader.discover().await.unwrap();
println!("{} plugins found", plugins.len());
Source

fn load<'life0, 'life1, 'async_trait>( &'life0 self, path: &'life1 Path, ) -> Pin<Box<dyn Future<Output = Result<(WasmPluginMeta, Arc<dyn ScrapingService>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load a single .wasm file by path.

§Example
let path = PathBuf::from("plugins/my-scraper.wasm");
let (meta, _svc) = loader.load(&path).await.unwrap();
println!("loaded: {} v{}", meta.name, meta.version);
Source

fn loaded<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<WasmPluginMeta>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List metadata for all currently loaded plugins (without reloading).

§Example
for meta in loader.loaded().await.unwrap() {
    println!("{} v{}", meta.name, meta.version);
}

Implementors§