Creates components whose exported functions return constant values.
Types
use type wasm
from componentized:component/types@0.1.0
The bytes of a WebAssembly binary, a component unless stated otherwise.
list<u8>
use variant error-code
from componentized:component/types@0.1.0
An error from a call.
malformed:malformedA value cannot be parsed to its expected type.
not-component:option<string>A wasm that must be a component is not, e.g. a core module. Calls accepting multiple wasms name the one that is not a component.
not-found:option<string>The item does not exist, optionally naming it, e.g. a path, URL, reference or package.
other:option<string>Any other error, with an optional message.
use record wit
from componentized:component/wit@0.1.0
The WIT of a component or WIT package.
interfaces:map<string, interface>Every interface, keyed by id.
packages:map<string, package>Every package, keyed by id.
types:map<string, type-def>Every type, keyed by id.
worlds:map<string, world>Every world, keyed by id.
default-package:package-idThe package that was parsed. For a component, the synthesized
root:componentpackage that contains the component's world.component-world:option<world-id>The world of the component, absent when a WIT package was parsed.
variant overrides
Values replacing those from the WIT. The overrides are a record with an optional field per world export. Interface exports are named by the interface and hold a nested record with a field per function.
wave:stringThe record as WAVE source,
//line comments are allowed.
Functions
create: async func(
wit: wit-source,
world: option<string>,
overrides: option<overrides>,
) -> result<wasm, error-code>
Creates a component implementing world from wit.
Every function the world exports must take no parameters and return a
value. Values can't reach maps, handles, futures, streams or error
contexts, though result types may include them in branches the value
doesn't take, e.g. none for an option<own<r>>. A function may
return a stream, written as a list of its items, which must be an
async function unless the stream is empty. Each function's value is a
WAVE expression following a @value tag in its doc comment. A stream
may continue with items generated by a Rust closure following an
@expression tag, e.g. |a, b| a + b, from the items before them,
starting from either its @value or the function's arguments.
world: the world to implement, required when the WIT package defines more than one world.overrides: values replacing those from the WIT.
WIT
/// Creates components whose exported functions return constant values.
interface factory {
use componentized:component/types@0.1.0.{wasm, error-code};
use componentized:component/wit@0.1.0.{wit, wit-source};
/// Values replacing those from the WIT. The overrides are a record with
/// an optional field per world export. Interface exports are named by the
/// interface and hold a nested record with a field per function.
variant overrides {
/// The record as WAVE source, `//` line comments are allowed.
wave(string),
}
/// Creates a component implementing `world` from `wit`.
///
/// Every function the world exports must take no parameters and return a
/// value. Values can't reach maps, handles, futures, streams or error
/// contexts, though result types may include them in branches the value
/// doesn't take, e.g. `none` for an `option<own<r>>`. A function may
/// return a stream, written as a list of its items, which must be an
/// async function unless the stream is empty. Each function's value is a
/// WAVE expression following a `@value` tag in its doc comment. A stream
/// may continue with items generated by a Rust closure following an
/// `@expression` tag, e.g. `|a, b| a + b`, from the items before them,
/// starting from either its `@value` or the function's arguments.
///
/// - `world`: the world to implement, required when the WIT package
/// defines more than one world.
/// - `overrides`: values replacing those from the WIT.
create: async func(wit: wit-source, %world: option<string>, overrides: option<overrides>) -> result<wasm, error-code>;
}