Skip to main content

Crate abi_adapter

Crate abi_adapter 

Source
Expand description

Slot-based wrappers for Wasm ABI boundaries.

Each slot is a Rust u32 and a Wasm i32; [u32; N] holds N slots.

§API

  • abi!: declare a host wrapper or guest export.
  • FromSlots: decode business arguments.
  • IntoSlots: encode business results.

Repository guides: docs/guide.md for usage and common problems and docs/architecture.md for design.

§Example

use abi_adapter::abi;

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

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

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

§Built-in conversions

These types implement both FromSlots and IntoSlots.

TypeSlotsRepresentation
()0[]
u321Unchanged
i321Original bits; -1 becomes 0xffff_ffff
f321to_bits / from_bits, without a numeric cast
[u32; N]NUnchanged, including N = 0

Implement the required direction for custom types. abi! directly returns only zero or one slot, regardless of a type’s other conversions.

§Constraints

The crate is no_std, has no dependencies, allocates no heap memory, and generates no unsafe blocks. User conversions and business functions retain their own allocation and error behavior. Guest declarations emit #[unsafe(export_name = ...)]; users must uphold the export-name and signature requirements documented by abi!.

Macros§

abi
Declare one host Rust wrapper or guest extern "C" export.

Traits§

FromSlots
Decode Self from exactly N slots.
IntoSlots
Encode Self as exactly N slots.