wasmtime/runtime/component/bindgen_examples/
_7_async.rs

1bindgen!({
2    inline: r#"
3        package example:imported-resources;
4
5        interface logging {
6            enum level {
7                debug,
8                info,
9                warn,
10                error,
11            }
12
13            resource logger {
14                constructor(max-level: level);
15
16                get-max-level: func() -> level;
17                set-max-level: func(level: level);
18
19                log: func(level: level, msg: string);
20            }
21        }
22
23        world import-some-resources {
24            import logging;
25        }
26    "#,
27
28    async: true, // NEW
29
30    with: {
31        // Specify that our host resource is going to point to the `MyLogger`
32        // which is defined just below this macro.
33        "example:imported-resources/logging/logger": MyLogger,
34    },
35
36    // Interactions with `ResourceTable` can possibly trap so enable the ability
37    // to return traps from generated functions.
38    trappable_imports: true,
39});
40
41/// A sample host-defined type which contains arbitrary host-defined data.
42///
43/// In this case this is relatively simple but there's no restrictions on what
44/// this type can hold other than that it must be `'static + Send`.
45pub struct MyLogger {
46    pub max_level: example::imported_resources::logging::Level,
47}