Debian Codegraph @

crates/wat/README.md

raw
1 <div align="center">
2 <h1><code>wat</code></h1>
3
4 <strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong>
5
6 <p>
7 <strong>A Rust parser for the <a href="https://webassembly.github.io/spec/core/text/index.html">WebAssembly Text Format (WAT)</a>.</strong>
8 </p>
9
10 <p>
11 <a href="https://crates.io/crates/wat"><img src="https://img.shields.io/crates/v/wat.svg?style=flat-square" alt="Crates.io version" /></a>
12 <a href="https://crates.io/crates/wat"><img src="https://img.shields.io/crates/d/wat.svg?style=flat-square" alt="Download" /></a>
13 <a href="https://docs.rs/wat/"><img src="https://img.shields.io/static/v1?label=docs&message=wat&color=blue&style=flat-square" alt="docs.rs docs" /></a>
14 <a href="https://docs.rs/wast/"><img src="https://img.shields.io/static/v1?label=docs&message=wast&color=blue&style=flat-square" alt="docs.rs docs" /></a>
15 </p>
16 </div>
17
18 ## Usage
19
20 Add `wat` to your `Cargo.toml`
21
22 ```sh
23 $ cargo add wat
24 ```
25
26 And then you can parse WAT to binary WebAssembly via:
27
28 ```rust
29 // Parse from a file ...
30 let binary = wat::parse_file("./foo.wat")?;
31
32 // ... or a string
33 let wat = r#"
34 (module
35 (func $foo)
36
37 (func (export "bar")
38 call $foo
39 )
40 )
41 "#;
42 let binary = wat::parse_str(wat)?;
43 ```
44
45 ## AST Representation
46
47 The `wat` crate does not expose an AST as its goal is to provide a
48 forever-stable interface against the `wast` crate. Using `wat` is suitable when
49 all you want to do is translate from text-to-binary, for example parsing the
50 input of a CLI program into the WebAssembly binary format.
51
52 If instead you're interested in working with the AST of a text file or otherwise
53 adding your own parsing to the text format you'll want to take a look at the
54 [`wast` crate](../wast/README.md).
55
56 ## Stability and WebAssembly Features
57
58 Consult the [crate documentation](https://docs.rs/wat) for more information,
59 but the general idea is this crate will not issue a semver-breaking change for
60 breaking changes in the WAT format, either for MVP features or post-MVP
61 features. No opt-in is required to use WebAssembly features, so using them may
62 break if the upstream spec changes.
63
64 # License
65
66 This project is licensed under the Apache 2.0 license with the LLVM exception.
67 See [LICENSE](LICENSE) for more details.
68
69 ### Contribution
70
71 Unless you explicitly state otherwise, any contribution intentionally submitted
72 for inclusion in this project by you, as defined in the Apache-2.0 license,
73 shall be licensed as above, without any additional terms or conditions.