#wasi #wasm #bus

macro wasmer-bus-macros

WebAssembly Bus Macros

1 stable release

1.1.0 Aug 8, 2022

#29 in #immutable-store

Download history 53/week @ 2023-07-17 46/week @ 2023-07-24 15/week @ 2023-07-31 37/week @ 2023-08-07 42/week @ 2023-08-14 14/week @ 2023-08-21 20/week @ 2023-08-28 49/week @ 2023-09-04 22/week @ 2023-09-11 28/week @ 2023-09-18 37/week @ 2023-09-25 30/week @ 2023-10-02 30/week @ 2023-10-09 34/week @ 2023-10-16 27/week @ 2023-10-23 35/week @ 2023-10-30

126 downloads per month
Used in 13 crates (via wasmer-bus)

MIT/Apache

56KB
1K SLoC

WASM Bus Macros

Helpful macros that make it easier to export and import APIs.

Example API

Below is a simple example of how to emit the helper classes and serialization objects for a specific API

use wasmer_bus::macros::*;

#[wasmer_bus(format = "json")]
pub trait Time {
    async fn sleep(&self, duration_ms: u128);
}

Relative Objects

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 wasmer_bus::macros::*;

#[wasmer_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>;
}

#[wasmer_bus(format = "bincode")]
pub trait WebSocket {
    async fn send(&self, data: Vec<u8>) -> SendResult;
}

Testing

You can test your WASI program by uploading it to wapm.io and then heading over to the Wasmer Shell

https://wasmer.sh

Dependencies

~0.6–1.2MB
~27K SLoC