abi-adapter 0.1.0

Mechanical slot-based ABI adapter for wasm boundaries
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented4 out of 4 items with examples
  • Size
  • Source code size: 113.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 162.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • vhexl/abi-adapter
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vhexl

abi-adapter

CI crates.io docs.rs MSRV License

English | 简体中文

Generate wasm interfaces for ordinary Rust functions. abi! converts arguments according to a declaration, calls the target, and converts its result. No third-party dependencies; supports no_std. Requires Rust 1.85+.

Quick start

Add the crate to your project:

cargo add abi-adapter

To use unreleased changes from main, depend on the Git repository instead:

cargo add abi-adapter --git https://github.com/vhexl/abi-adapter
use abi_adapter::abi;

fn double(value: u32) -> u32 {
    value * 2
}

abi! { host pub fn double_abi([value]) -> 1 => crate::double; }

fn main() {
    assert_eq!(double_abi(21), 42);
}

host generates a regular Rust function; guest("double.v1") generates a wasm export. Each bracketed group maps to one target argument. Slots are Rust u32 values and wasm i32 values; wrappers directly return zero or one slot. Custom types use FromSlots<N> and IntoSlots<N>. For a complete wasm example, see examples/guest.rs.

Users define runtime registration, memory protocols, and error codes. Panics from conversions and target functions are not caught; guest exports trap.

Documentation

The following guides are in Chinese:

License

MIT or Apache-2.0, at your option.