#bus #wasi #wasm

wasmer-bus-macros

WebAssembly总线宏

1 个稳定版本

1.1.0 2022年8月8日

#89#bus

Download history 27/week @ 2024-03-11 31/week @ 2024-03-18 35/week @ 2024-03-25 65/week @ 2024-04-01 19/week @ 2024-04-08 17/week @ 2024-04-15 29/week @ 2024-04-22 35/week @ 2024-04-29 17/week @ 2024-05-06 31/week @ 2024-05-13 19/week @ 2024-05-20 31/week @ 2024-05-27 27/week @ 2024-06-03 20/week @ 2024-06-10 19/week @ 2024-06-17 30/week @ 2024-06-24

96 每月下载量
13 个crate中使用(通过 wasmer-bus

MIT/Apache

81KB
1.5K SLoC

WASM总线宏

有助于导出和导入API的有用宏。

示例API

以下是一个简单示例,说明如何生成特定API的辅助类和序列化对象

use wasmer_bus::macros::*;

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

相对对象

还可以生成一系列带有特定上下文的子API

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;
}

测试

您可以通过上传到wapm.io并前往Wasmer Shell来测试您的WASI程序。

https://wasmer.sh

依赖关系

~2MB
~41K SLoC