93 stable releases

new 1.206.0 Apr 25, 2024
1.202.0 Mar 26, 2024
1.0.82 Nov 29, 2023
1.0.69 Jul 26, 2023
0.1.0 Sep 23, 2016

#90 in WebAssembly

Download history 73383/week @ 2024-01-03 83197/week @ 2024-01-10 92713/week @ 2024-01-17 87033/week @ 2024-01-24 94325/week @ 2024-01-31 86711/week @ 2024-02-07 82630/week @ 2024-02-14 89403/week @ 2024-02-21 94472/week @ 2024-02-28 96513/week @ 2024-03-06 94848/week @ 2024-03-13 98801/week @ 2024-03-20 91243/week @ 2024-03-27 106312/week @ 2024-04-03 113910/week @ 2024-04-10 80630/week @ 2024-04-17

408,414 downloads per month
Used in 410 crates (109 directly)

Apache-2.0 WITH LLVM-exception

655KB
15K SLoC

wat

A Bytecode Alliance project

A Rust parser for the WebAssembly Text Format (WAT).

Crates.io version Download docs.rs docs docs.rs docs

Usage

Add wat to your Cargo.toml

$ cargo add wat

And then you can parse WAT to binary WebAssembly via:

// Parse from a file ...
let binary = wat::parse_file("./foo.wat")?;

// ... or a string
let wat = r#"
    (module
        (func $foo)

        (func (export "bar")
            call $foo
        )
    )
"#;
let binary = wat::parse_str(wat)?;

AST Representation

The wat crate does not expose an AST as its goal is to provide a forever-stable interface against the wast crate. Using wat is suitable when all you want to do is translate from text-to-binary, for example parsing the input of a CLI program into the WebAssembly binary format.

If instead you're interested in working with the AST of a text file or otherwise adding your own parsing to the text format you'll want to take a look at the wast crate.

Stability and WebAssembly Features

Consult the crate documentation for more information, but the general idea is this crate will not issue a semver-breaking change for breaking changes in the WAT format, either for MVP features or post-MVP features. No opt-in is required to use WebAssembly features, so using them may break if the upstream spec changes.

License

This project is licensed under the Apache 2.0 license with the LLVM exception. See LICENSE for more details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Dependencies

~1MB
~16K SLoC