Skip to main content

PluginData

Trait PluginData 

Source
pub trait PluginData:
    Sized
    + Send
    + PluginCtxView {
    type Id: Clone + Hash + Eq + Debug + Send + Sync;
    type InterfaceId: Clone + Hash + Eq + Display;
    type Error: Error;
    type SocketIter<'a>: IntoIterator<Item = &'a Self::InterfaceId>
       where Self: 'a;

    // Required methods
    fn id(&self) -> Result<&Self::Id, Self::Error>;
    fn plug(&self) -> Result<&Self::InterfaceId, Self::Error>;
    fn sockets(&self) -> Result<Self::SocketIter<'_>, Self::Error>;
    fn component(&self, engine: &Engine) -> Result<Component, Self::Error>;
}
Expand description

Trait for accessing plugin metadata and WASM binaries from a user-defined source.

Implement this trait to define how plugins are discovered, how their metadata is read, and how their WASM binaries are loaded.

Each plugin declares:

  • A plug: the interface it implements (what it exports)
  • Zero or more sockets: interfaces it depends on (what it imports)

During loading, the framework uses this information to build the dependency graph and link plugins together.

§Associated Types

  • Id: Unique identifier type for plugins (e.g., String, Uuid, PathBuf)
  • InterfaceId: Must match the Id type used by your InterfaceData implementation
  • Error: The error type returned when metadata access or compilation fails
  • SocketIter: Iterator over the interface IDs this plugin depends on

Required Associated Types§

Source

type Id: Clone + Hash + Eq + Debug + Send + Sync

A type used as a unique identifier for a plugin

Source

type InterfaceId: Clone + Hash + Eq + Display

A type used as a unique identifier for an interface

Source

type Error: Error

Error type for metadata access and compilation failures.

Source

type SocketIter<'a>: IntoIterator<Item = &'a Self::InterfaceId> where Self: 'a

Iterator over interface IDs this plugin depends on (its sockets).

Required Methods§

Source

fn id(&self) -> Result<&Self::Id, Self::Error>

Returns this plugin’s unique identifier.

§Errors

Implementations may fail if the underlying data source is unavailable.

Source

fn plug(&self) -> Result<&Self::InterfaceId, Self::Error>

Returns the interface ID that this plugin implements (its plug).

The plug declares which interface this plugin provides an implementation for. The plugin must export all functions declared by this interface.

§Errors

Implementations may fail if the underlying data source is unavailable.

Source

fn sockets(&self) -> Result<Self::SocketIter<'_>, Self::Error>

Returns the interface IDs that this plugin depends on (its sockets).

Each socket is an interface the plugin expects to call into. During linking, these calls are wired to the plugin(s) implementing each interface.

§Errors

Implementations may fail if the underlying data source is unavailable.

Source

fn component(&self, engine: &Engine) -> Result<Component, Self::Error>

Compiles this plugin’s WASM binary into a wasmtime Component.

Called during PluginTree::load to compile the plugin. The implementation is responsible for locating and reading the WASM binary.

§Errors

May fail due to I/O errors reading the WASM source, or wasmtime compilation errors if the binary is invalid or incompatible.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§