Crates.io | wasm-bus-macros |
lib.rs | wasm-bus-macros |
version | 1.1.0 |
source | src |
created_at | 2022-01-02 14:23:13.151273 |
updated_at | 2022-03-06 23:02:24.438444 |
description | WebAssembly Bus Macros |
homepage | |
repository | https://github.com/john-sharratt/ate |
max_upload_size | |
id | 506558 |
size | 56,156 |
Helpful macros that make it easier to export and import APIs.
Below is a simple example of how to emit the helper classes and serialization objects for a specific API
use wasm_bus::macros::*;
#[wasm_bus(format = "json")]
pub trait Time {
async fn sleep(&self, duration_ms: u128);
}
It is also possible to emit a series of sub-apis that carry with them some specific context
use serde::*;
use std::sync::Arc;
use wasm_bus::macros::*;
#[wasm_bus(format = "bincode")]
pub trait SocketBuilder {
async fn connect(
&self,
url: String,
state_change: impl Fn(SocketState),
receive: impl Fn(Vec<u8>),
) -> Arc<dyn WebSocket>;
}
#[wasm_bus(format = "bincode")]
pub trait WebSocket {
async fn send(&self, data: Vec<u8>) -> SendResult;
}
You can test your WASI program by uploading it to wapm.io and then heading over to the Tokera Shell