29 lines
1.2 KiB
Rust
29 lines
1.2 KiB
Rust
|
//! This module defines backends for WebAssembly execution.
|
||
|
//!
|
||
|
//! Canary is designed to support multiple WebAssembly runtimes for different
|
||
|
//! purposes. Currently, [wasmtime](https://wasmtime.dev) is the only one
|
||
|
//! implemented, but in the future, [wasm3](https://github.com/wasm3/wasm3)
|
||
|
//! will also be provided.
|
||
|
|
||
|
use super::*;
|
||
|
|
||
|
/// A WebAssembly runtime backend.
|
||
|
pub trait Backend {
|
||
|
fn load_module(&self, module: &[u8]) -> Arc<dyn Instance>;
|
||
|
}
|
||
|
|
||
|
/// An instance of a WebAssembly module.
|
||
|
///
|
||
|
/// All self parameters to this trait's functions are immutable, so the
|
||
|
/// implementation must provide interior mutability. This allows instances
|
||
|
/// to intelligently optimize the execution of their scripts, for example, by
|
||
|
/// allowing the execution of multiple ABI calls from multiple threads when
|
||
|
/// a script supports the WebAssembly multithreading extension.
|
||
|
pub trait Instance {
|
||
|
fn bind_panel(&self, panel: PanelId, msg: Vec<u8>) -> u32;
|
||
|
fn update(&self, panel: PanelId, dt: f32);
|
||
|
fn draw(&self, panel: PanelId) -> Vec<DrawCommand>;
|
||
|
fn on_cursor_event(&self, panel: PanelId, kind: CursorEventKind, at: Vec2);
|
||
|
fn on_message(&self, panel: PanelId, msg: Vec<u8>);
|
||
|
}
|