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:InterfaceDataimplementation for loading interface metadataP:PluginDataimplementation 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,
impl<I, P, InterfaceId> PluginTree<I, P>where
I: InterfaceData<Id = InterfaceId> + InterfaceData,
P: PluginData<InterfaceId = InterfaceId> + PluginData,
InterfaceId: Clone + Hash + Eq + Display,
Sourcepub fn new(
root_interface_id: I::Id,
interfaces: impl IntoIterator<Item = I>,
plugins: impl IntoIterator<Item = P>,
) -> PartialSuccess<Self, PluginTreeError<I, P>>
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::plugreturns an error
§Panics
Panics if an interface with id root_interface_id is not present in interfaces.
Sourcepub fn from_socket_map(
root_interface_id: I::Id,
socket_map: HashMap<I::Id, (I, Vec<P>)>,
) -> Self
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.
Sourcepub fn load(
self,
engine: &Engine,
exports: &Linker<P>,
) -> PartialResult<PluginTreeHead<I, P>, LoadError<I, P>, LoadError<I, P>>
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>
impl<I, P> RefUnwindSafe for PluginTree<I, P>
impl<I, P> Send for PluginTree<I, P>
impl<I, P> Sync for PluginTree<I, P>
impl<I, P> Unpin for PluginTree<I, P>
impl<I, P> UnwindSafe for PluginTree<I, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<X> Pipe for X
impl<X> Pipe for X
Source§fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Returnwhere
Function: FnOnce(&'a Self) -> Return,
fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Returnwhere
Function: FnOnce(&'a Self) -> Return,
Source§fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Returnwhere
Function: FnOnce(&'a mut Self) -> Return,
fn pipe_mut<'a, Return, Function>(&'a mut self, f: Function) -> Returnwhere
Function: FnOnce(&'a mut Self) -> Return,
Source§fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
fn pipe_as_ref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
f to &self where f takes a single parameter of type Param
and Self implements trait AsRef<Param>. Read moreSource§fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return
fn pipe_as_mut<'a, Param, Return, Function>(&'a mut self, f: Function) -> Return
f to &mut self where f takes a single parameter of type Param
and Self implements trait AsMut<Param>. Read moreSource§fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
fn pipe_deref<'a, Param, Return, Function>(&'a self, f: Function) -> Return
f to &self where f takes a single parameter of type Param
and Self implements trait Deref<Target = Param>. Read moreSource§fn pipe_deref_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function,
) -> Returnwhere
Self: DerefMut<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return,
fn pipe_deref_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function,
) -> Returnwhere
Self: DerefMut<Target = Param>,
Param: 'a + ?Sized,
Function: FnOnce(&'a mut Param) -> Return,
f to &mut self where f takes a single parameter of type Param
and Self implements trait DerefMut<Target = Param>. Read moreSource§fn pipe_borrow<'a, Param, Return, Function>(&'a self, f: Function) -> Return
fn pipe_borrow<'a, Param, Return, Function>(&'a self, f: Function) -> Return
f to &self where f takes a single parameter of type Param
and Self implements trait Borrow<Param>. Read moreSource§fn pipe_borrow_mut<'a, Param, Return, Function>(
&'a mut self,
f: Function,
) -> Return
fn pipe_borrow_mut<'a, Param, Return, Function>( &'a mut self, f: Function, ) -> Return
f to &mut self where f takes a single parameter of type Param
and Self implements trait BorrowMut<Param>. Read more