Crates.io | wings_marshal |
lib.rs | wings_marshal |
version | 0.1.5 |
source | src |
created_at | 2024-05-08 22:26:57.107103 |
updated_at | 2024-08-16 19:35:49.175614 |
description | WASM plugin system for Geese. |
homepage | |
repository | https://github.com/DouglasDwyer/wings |
max_upload_size | |
id | 1234650 |
size | 25,088 |
Wings is a WASM plugin system for Rust. It integrates directly with the Geese event library, allowing plugins to seamlessly communicate with one another and the host using events and systems. The following features are supported:
The following is an abridged example of how to use Wings. The complete code may be found in the wings_example
folder.
Wings allows for defining traits like the following, which can be shared between the code of hosts and between plugins:
// Define a system that the host will expose.
// This can also be used to expose guest systems to other guest systems.
#[system_trait(host)]
pub trait ExampleSystem: 'static {
// Prints a value to the console.
fn print(&self, value: &str);
}
Then, the system may be referenced as a trait object from WASM:
// Define a Wings system that will run within WASM
#[export_system]
pub struct PluginSystem;
impl WingsSystem for PluginSystem {
// Declare a dependency on the exported host system
const DEPENDENCIES: Dependencies = dependencies()
.with::<dyn ExampleSystem>();
// Invoked when the plugin is created
fn new(mut ctx: WingsContextHandle<Self>) -> Self {
// Get the system from WASM and invoke its function
ctx.get::<dyn ExampleSystem>().print(&format!("Hello from WASM!"));
Self
}
}
Finally, the system may be implemented on the host and exposed to plugins:
// Define a host type
pub struct TestHost;
impl Host for TestHost {
// Declare the systems that should be exported to WASM,
// and the traits under which they should be exported
const SYSTEMS: Systems<Self> = systems()
.with::<ExampleSystemImpl>(traits()
.with::<dyn example_host_system::ExampleSystem>());
...
}
// Declare an implementation for the WASM-exported system
pub struct ExampleSystemImpl;
impl ExampleSystem for ExampleSystemImpl {
fn print(&self, value: &str) {
println!("Plugin says '{value}'");
}
}
In general, anything possible with vanilla Geese is also possible with Wings. See the example for demonstration of more functionality.