Available on crate feature
runtime
and crate feature component-model
and docsrs
only.Expand description
Example of generating bindings for imported interfaces in a world.
Notable parts of this example are:
- Imported interfaces use the Rust module system to encapsulate themselves.
The interface imported here is
example:interface-imports/logging
so the generated trait and types are located inexample::interface_imports::logging
. - Types in the
logging
interface are generated in thelogging
module, for exampleLevel
. - Generated types have implementations of
ComponentType
,Lift
, andLower
derived. - The generated trait that host’s must implement is always called
Host
and is located in the generated module.
use wasmtime::component::bindgen;
use example::interface_imports::logging::Level;
bindgen!({
inline: r#"
package example:interface-imports;
interface logging {
enum level {
debug,
info,
warn,
error,
}
log: func(level: level, msg: string);
}
world with-imports {
import logging;
}
"#,
});
struct MyState {
// ...
}
impl example::interface_imports::logging::Host for MyState {
fn log(&mut self, level: Level, msg: String) {
// ...
}
}
Modules§
Structs§
- Auto-generated bindings for an instance a component which implements the world
with-imports
. - Auto-generated bindings for index of the exports of
with-imports
. - Auto-generated bindings for a pre-instantiated version of a component which implements the world
with-imports
.