15 unstable releases (7 breaking)

0.8.1 Jan 22, 2024
0.7.0 Jan 17, 2024
0.6.0 Mar 10, 2023
0.3.1 Aug 18, 2021
0.2.2 Oct 22, 2020

#91 in WebAssembly

Download history 1280/week @ 2024-07-20 829/week @ 2024-07-27 1511/week @ 2024-08-03 1198/week @ 2024-08-10 1474/week @ 2024-08-17 1271/week @ 2024-08-24 1169/week @ 2024-08-31 1235/week @ 2024-09-07 1335/week @ 2024-09-14 2232/week @ 2024-09-21 4537/week @ 2024-09-28 3870/week @ 2024-10-05 6457/week @ 2024-10-12 6622/week @ 2024-10-19 7401/week @ 2024-10-26 7745/week @ 2024-11-02

29,272 downloads per month
Used in spacetimedb-cli

Apache-2.0

115KB
2.5K SLoC

wasmbin

wasmbin is a library implementing low-level parsing and serialization of WebAssembly binaries.

Public API

The entry point is the Module object.

From there you can explore the module contents by simply looking up the nested fields. The structures map pretty much 1:1 to raw WebAssembly binary format, so you can also use the specification as a reference.

Supported feature extensions

Following WebAssembly proposals are supported in addition to the core spec and can be enabled via corresponding Cargo features:

Motivation

Original blog post explaining motivation and internals: wasmbin: a self-generating WebAssembly parser & serializer.

This crate intends to provide a low-level representation of the WebAssembly module that is fully described by Rust type system. It also leverages the said type system in conjunction with custom proc-macros to autogenerate parsing/serialization/visitation code for any complex types (structures and enums).

On the user's side this approach allows any type can be used independently to represent/parse/serialize only part of the module, while on the maintainers' side it makes adding and testing new WebAssembly features as quick and easy as adding new types, fields, and variants, without having to write any manual code at all.

One other notable feature is a Lazy<T> wrapper used in wasmbin whenever the spec permits efficiently skipping over some contents (e.g. function bodies). It allows minimally invasive, efficient, "zero-cost" editing of WebAssembly modules: during decoding anything that can be skipped, is skipped over lazily (the Lazy<...> container simply stores the raw bytes), and during encoding only the modified parts of the module are re-encoded, while any untouched parts are copied verbatim as raw bytes from the source.

Dependencies

~1.1–1.7MB
~35K SLoC