Module wasmtime::component::bindgen_examples

source ·
Available on crate feature runtime and crate feature component-model and docsrs only.
Expand description

Examples of output of the bindgen! macro.

This module is only included in docs.rs documentation and is not present in the actual crate when compiling from crates.io. The purpose of this module is to showcase what the output of the bindgen! macro looks like and some examples of how to use it.

If you’re confused or lost in bindgen! feel free to open an issue with a description of your issue and it can hopefully lead to a new example being added here for others to use as reference.

§Including *.wit files in your project

Note that most of the examples in this module will use the inline key of the bindgen! macro. This is done as it’s easy to show the example and WIT all in one self-contained snippet of Rust code. Typically though a project will have a wit directory next to Cargo.toml which contains WIT files.

The general layout of a wit directory is that:

  • All *.wit files at wit/*.wit are parsed and included in the same package.
  • If the wit/deps folder is present then it can either contain:
    • Subdirectories with a package-per-directory. For example wit/deps/wasi-http and wit/deps/wasi-cli.
    • WIT files that are a single-file rendering of a package, for example wit/deps/wasi-http.wit
    • WIT packages encoded as WebAssembly binaries for a package, for example wit/deps/wasi-http.wasm

This means that at this time you’ll need to copy around *.wit files or WIT packages encoded as *.wasm and check them in to your project’s wit directory. The hope is that in the future it will be easier to manage these files with registry tooling and they won’t have to be copied manually. For reference documentation on the layout of the wit directory see wit_parser::Resolve::push_dir.

Modules§