Skip to main content

machine

Attribute Macro machine 

Source
#[machine]
Expand description

Setup attribute for functions whose body contains a banish! { } block.

#[banish::machine] takes no arguments and does three things automatically:

  • Sets id in the block attribute to the function name, so trace output is labelled without any extra boilerplate. Can be overridden by writing #![id = "name"] inside the banish! block explicitly.

  • Injects async into the block attribute when applied to an async fn, so #![async] does not need to be written manually. Writing it explicitly is also fine. The attribute detects it and skips injection.

  • Injects .await on the banish! expression when the function is async, so the future produced by #![async] is driven to completion automatically. If .await is 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"; }
            }
    }
}