bytecodealliance / bytecodealliance/wasmtime
wasmtime::component::bindgen: How to specify a resource in "imports:"?
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
In the documentation [here](https://docs.wasmtime.dev/api/wasmtime/component/macro.bindgen.html) there are examples of imported interfaces, but not of resources in the interfaces.
Specificaly I want to mark only the resource as `async`. I've tried various notations to no avail.
Given this world:
```
package floria:plugins;
world dispatch-plugin {
import floria;
}
interface floria {
resource session {
constructor();
get-entity: func(id: string) -> result;
}
```
Here are my bindings:
```rust
wasmtime::component::bindgen!({
path: "assets/wit/floria-plugins.wit",
imports: {
// "floria:plugins/floria.session": async | trappable,
default: trappable,
}
});
```
The commented-out line is one of my attempts. :) However, I get errors such as this:
```
unused `imports` rules found: ["\"floria:plugins/floria.session\": FunctionFlags(ASYNC | TRAPPABLE)"]
```
What is the correct notation for referring to resources in `imports`? Is it even possible?
Note that I truncated the WIT file here. In fact I have many more imports, which I do *not* want to be `async`.
Contributor guide
Research direction
Start with the wasmtime::component::bindgen documentation and the imports rules shown in the issue, then reproduce the example using assets/wit/floria-plugins.wit. Determine whether resources can be selected independently for async handling, and document the supported notation or limitation with a resource-specific example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- devtools, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100