Module wasmtime::component

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

§Embedding API for the Component Model

This module contains the embedding API for the Component Model in Wasmtime. This module requires the component-model feature to be enabled, which is enabled by default. The embedding API here is mirrored after the core wasm embedding API at the crate root and is intended to have the same look-and-feel while handling concepts of the component model.

The component model is a broad topic which can’t be explained here fully, so it’s recommended to read over individual items’ documentation to see more about the capabilities of the embedding API. At a high-level, however, perhaps the most interesting items in this module are:

  • Component - a compiled component ready to be instantiated. Similar to a Module for core wasm.

  • Linker - a component-style location for defining host functions. This is not the same as wasmtime::Linker for core wasm modules.

  • bindgen! - a macro to generate Rust bindings for a WIT world. This maps all WIT types into Rust automatically and generates traits for embedders to implement.

Embedders of the component model will typically start by defining their API in WIT. This describes what will be available to guests and what needs to be provided to the embedder by the guest. This world that was created is then fed into bindgen! to generate types and traits for the embedder to use. The embedder then implements these traits, adds functionality via the generated add_to_linker method (see bindgen! for more info), and then instantiates/executes a component.

It’s recommended to read over the documentation for the Component Model to get an overview about how to build components from various languages.

Modules§

  • This module defines the Type type, representing the dynamic form of a component interface type.

Macros§

Structs§

  • A compiled WebAssembly Component.
  • Dynamic representation of enum in the component model.
  • Description of the exports of a single instance.
  • Description of the exports of an Instance.
  • Dynamic representation of flags in the component model.
  • A WebAssembly component function which can be called.
  • An instantiated component.
  • A “pre-instantiated” Instance which has all of its arguments already supplied and is ready to instantiate.
  • A type used to instantiate Components.
  • Structure representing an “instance” being defined within a linker.
  • Dynamic representation of list<T> in the component model.
  • Dynamic representation of option<T> in the component model.
  • Dynamic representation of record in the component model.
  • A host-defined resource in the component model.
  • Representation of a resource in the component model, either a guest-defined or a host-defined resource.
  • Index correlating a resource definition to the import path. This is assigned by Linker::resource and may be used to associate it to RuntimeImportIndex at a later stage
  • The ResourceTable type maps a Resource<T> to its T.
  • Representation of a resource type in the component model.
  • Dynamic representation of result<T, E> in the component model.
  • Dynamic representation of tuple<...> in the component model.
  • A statically-typed version of Func which takes Params as input and returns Return.
  • Dynamic representation of variant in the component model.
  • Representation of a list of values that are owned by a WebAssembly instance.
  • Representation of a string located in linear memory in a WebAssembly instance.

Enums§

  • Errors returned by operations on ResourceTable
  • Represents a component model interface type
  • Represents possible runtime values which a component function can either consume or produce

Traits§

  • A trait representing a static list of named types that can be passed to or returned from a TypedFunc.
  • A trait representing types which can be passed to and read from components with the canonical ABI.
  • Host types which can be created from the canonical ABI.
  • Host types which can be passed to WebAssembly components.

Derive Macros§