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
*.witfiles atwit/*.witare parsed and included in the same package. - If the
wit/depsfolder is present then it can either contain:- Subdirectories with a package-per-directory. For example
wit/deps/wasi-httpandwit/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
- Subdirectories with a package-per-directory. For example
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§
- _0_
hello_ world - A “hello world” style example.
- _1_
world_ imports - An example of generated bindings for top-level imported functions and interfaces into a world.
- _2_
world_ exports - An example of generated bindings for top-level exported functions for a world.
- _3_
interface_ imports - Example of generating bindings for imported interfaces in a world.
- _4_
imported_ resources - Example of generating bindings for imported resources in a world.
- _5_
all_ world_ export_ kinds - Example of all kinds of structures of exports from a world.
- _6_
exported_ resources - Example of a world which exports a resource.
- _7_
async - Example of generating async bindings for imported resources in a world.
- _8_
store_ in_ imports component-model-async - Example of using
StoreContextMutin imported functions.