Skip to main content

PluginTree

Struct PluginTree 

Source
pub struct PluginTree<I: InterfaceData, P: PluginData> { /* private fields */ }
Expand description

An unloaded plugin dependency tree.

Built from a list of plugins by grouping them according to the interfaces they implement (their plug) and depend on (their sockets). The structure has a single root interface and cycles are forbidden, so it can be thought of as a tree (though internally, multiple plugins may share a dependency).

This is the pre-compilation representation - no WASM has been loaded yet.

Call load to compile WASM components and link dependencies, producing a PluginTreeHead for dispatching function calls.

§Type Parameters

  • I: InterfaceData implementation for loading interface metadata
  • P: PluginData implementation for loading plugin metadata

§Example

use wasm_link::{
    InterfaceData, InterfaceCardinality, FunctionData, ReturnKind,
    PluginData, PluginCtxView, PluginTree, Engine, Component, Linker, ResourceTable,
};

struct Interface { id: &'static str, funcs: Vec<Func> }
impl InterfaceData for Interface {
    /* ... */
}

struct Plugin { id: &'static str, plug: &'static str, resource_table: ResourceTable }
impl PluginData for Plugin {
    /* ... */
}

let root_interface_id = "root" ;
let plugins = [ Plugin { id: "foo", plug: root_interface_id, resource_table: ResourceTable::new() }];
let interfaces = [ Interface { id: root_interface_id, funcs: vec![] }];

// Build the dependency graph
let ( tree, build_errors ) = PluginTree::new( root_interface_id, interfaces, plugins );
assert!( build_errors.is_empty() );

// Compile and link the plugins
let engine = Engine::default();
let linker = Linker::new( &engine );
let ( tree_head, load_errors ) = tree.load( &engine, &linker ).unwrap();
assert!( load_errors.is_empty() );

Implementations§

Source§

impl<I, P, InterfaceId> PluginTree<I, P>
where I: InterfaceData<Id = InterfaceId> + InterfaceData, P: PluginData<InterfaceId = InterfaceId> + PluginData, InterfaceId: Clone + Hash + Eq + Display,

Source

pub fn new( root_interface_id: I::Id, interfaces: impl IntoIterator<Item = I>, plugins: impl IntoIterator<Item = P>, ) -> PartialSuccess<Self, PluginTreeError<I, P>>

Builds a plugin dependency graph from the given interfaces and plugins.

Plugins are grouped by the interface they implement ( via PluginData::plug ). Interfaces are indexed by their PluginData::id method.

The root_interface_id specifies the entry point of the tree - the interface whose plugins will be directly accessible via PluginTreeHead::dispatch after loading.

Does not validate all interfaces required for linking are present. Does not validate cardinality requirements.

§Partial Success

Attempts to construct a tree for all plugins it received valid data for. Returns a list of errors alongside the loaded PluginTree is any of the following occurs:

  • An Interface mentioned in a plugin’s plug is not passed in
  • Calling PluginData::plug returns an error
§Panics

Panics if an interface with id root_interface_id is not present in interfaces.

Source

pub fn from_socket_map( root_interface_id: I::Id, socket_map: HashMap<I::Id, (I, Vec<P>)>, ) -> Self

Creates a plugin tree directly from a pre-built socket map.

Does not validate all interfaces required for linking are present. Does not validate cardinality requirements.

§Panics

Panics if an interface with id root_interface_id is not present in interfaces.

Source

pub fn load( self, engine: &Engine, exports: &Linker<P>, ) -> PartialResult<PluginTreeHead<I, P>, LoadError<I, P>, LoadError<I, P>>

Compiles and links all plugins in the tree, returning a loaded tree head.

This recursively loads plugins starting from the root interface, compiling WASM components and linking their dependencies.

§Errors

Returns LoadError variants for:

  • Invalid or missing socket interfaces
  • Dependency cycles between plugins
  • Cardinality violations (too few/many plugins for an interface)
  • Corrupted interface or plugin manifests
  • WASM compilation or linking failures

Auto Trait Implementations§

§

impl<I, P> Freeze for PluginTree<I, P>
where <I as InterfaceData>::Id: Freeze,

§

impl<I, P> RefUnwindSafe for PluginTree<I, P>

§

impl<I, P> Send for PluginTree<I, P>
where <I as InterfaceData>::Id: Send, I: Send,

§

impl<I, P> Sync for PluginTree<I, P>
where <I as InterfaceData>::Id: Sync, I: Sync, P: Sync,

§

impl<I, P> Unpin for PluginTree<I, P>
where <I as InterfaceData>::Id: Unpin, I: Unpin, P: Unpin,

§

impl<I, P> UnwindSafe for PluginTree<I, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<X> Pipe for X

Source§

fn pipe<Return, Function>(self, f: Function) -> Return
where Self: Sized, Function: FnOnce(Self) -> Return,

Apply f to self. Read more
Source§

fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Return
where Function: FnOnce(&'a Self) -> Return,

Apply f to &self. Read more
Source§

fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Return
where Function: FnOnce(&'a mut Self) -> Return,

Apply f to &mut self. Read more
Source§

fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
where Self: AsRef<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a Param) -> Return,

Apply f to &self where f takes a single parameter of type Param and Self implements trait AsRef<Param>. Read more
Source§

fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return
where Self: AsMut<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a mut Param) -> Return,

Apply f to &mut self where f takes a single parameter of type Param and Self implements trait AsMut<Param>. Read more
Source§

fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
where Self: Deref<Target = Param>, Param: 'a + ?Sized, Function: FnOnce(&'a Param) -> Return,

Apply f to &self where f takes a single parameter of type Param and Self implements trait Deref<Target = Param>. Read more
Source§

fn pipe_deref_mut<'a, Param, Return, Function>( &'a mut self, f: Function, ) -> Return
where Self: DerefMut<Target = Param>, Param: 'a + ?Sized, Function: FnOnce(&'a mut Param) -> Return,

Apply f to &mut self where f takes a single parameter of type Param and Self implements trait DerefMut<Target = Param>. Read more
Source§

fn pipe_borrow<'a, Param, Return, Function>(&'a self, f: Function) -> Return
where Self: Borrow<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a Param) -> Return,

Apply f to &self where f takes a single parameter of type Param and Self implements trait Borrow<Param>. Read more
Source§

fn pipe_borrow_mut<'a, Param, Return, Function>( &'a mut self, f: Function, ) -> Return
where Self: BorrowMut<Param>, Param: 'a + ?Sized, Function: FnOnce(&'a mut Param) -> Return,

Apply f to &mut self where f takes a single parameter of type Param and Self implements trait BorrowMut<Param>. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.