No description
|
|
||
|---|---|---|
| examples | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
IXT WASM Module SDK
Ergonomic SDK for building WASM modules that run in the IXT runtime.
Quick Start
#![no_std]
use ixt_sdk_wasm::prelude::*;
struct Echo;
impl Default for Echo {
fn default() -> Self { Self }
}
impl WasmModule for Echo {
fn handle(&mut self, payload: &[u8], _ctx: &MsgContext) -> HandleResult {
HandleResult::reply(payload)
}
}
ixt_wasm_module!(Echo);
Build: cargo build --target wasm32-unknown-unknown --release
The resulting .wasm file goes into your module bundle at bin/wasm/any/module.wasm.
What the SDK Does For You
| Concern | Without SDK | With SDK |
|---|---|---|
| Memory allocation | Manual ixt_alloc/ixt_free in every module |
Provided by SDK |
| Panic handling | Manual #[panic_handler] in every module |
Provided by SDK |
| Host functions | Raw extern "C" with i32 pointers |
Safe host::send(), host::kv_get_str(), etc. |
| ABI exports | Manual #[no_mangle] pub unsafe extern "C" fn |
ixt_wasm_module!(MyModule) |
| Message context | Not available | ctx.topic(), ctx.sender() |
Host Functions
// MessageBus
host::send("topic", payload)?;
let response = host::request("topic", payload)?;
// KV Store
host::kv_set_str("key", "value")?;
let val = host::kv_get_str("key")?;
host::kv_del("key")?;
// Events
host::subscribe("events.*")?;
host::publish("events.my-event", payload)?;
// Logging
host::log_info("hello");
host::log_error("something went wrong");
// Assets
let path = host::resolve_asset("data/model.bin")?;
License
MIT