Add backend module

This commit is contained in:
mars 2022-11-02 16:25:12 -06:00
parent 70a4d5b49b
commit 4061af264d
2 changed files with 29 additions and 0 deletions

28
src/backend/mod.rs Normal file
View File

@ -0,0 +1,28 @@
//! 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>);
}

View File

@ -7,6 +7,7 @@ use slab::Slab;
use std::collections::HashMap;
use std::sync::Arc;
pub mod backend;
pub mod text;
/// Proportion constant between pixels (at 96dpi) to millimeters (Canary's unit measurement).