#[machine]Expand description
Setup attribute for functions whose body contains a banish! { } block.
#[banish::machine] takes no arguments and does three things automatically:
-
Sets
idin the block attribute to the function name, so trace output is labelled without any extra boilerplate. Can be overridden by writing#![id = "name"]inside thebanish!block explicitly. -
Injects
asyncinto the block attribute when applied to anasync fn, so#![async]does not need to be written manually. Writing it explicitly is also fine. The attribute detects it and skips injection. -
Injects
.awaiton thebanish!expression when the function is async, so the future produced by#![async]is driven to completion automatically. If.awaitis already present it is left alone.
ยงExample
// `async` and id = "fetch" are both injected automatically.
#[banish::machine]
async fn fetch() -> &'static str {
banish! {
@check
ping? {
let ok = reqwest::get("https://example.com").await.is_ok();
if ok { return "Up"; } else { return "Down"; }
}
}
}