bindgen!({
inline: r#"
package example:resource-async;
interface logging {
enum level {
debug,
info,
warn,
error,
}
resource logger {
constructor(max-level: level);
get-max-level: func() -> level;
set-max-level: func(level: level);
/// May block if the host's log buffer is full (i.e. backpressure).
log: async func(level: level, msg: string);
}
}
world app {
import logging;
/// Because `logging.logger.log` is async, `run` must also be async; otherwise,
/// a trap will occur at runtime if `run` calls `log` and it blocks.
export run: async func();
}
"#,
imports: {
default: trappable,
},
with: {
"example:resource-async/logging.logger": MyLogger,
},
});
pub struct MyLogger {
pub max_level: example::resource_async::logging::Level,
}