Skip to main content

run

Attribute Macro run 

Source
#[run]
Expand description

Attribute macro that wraps a function body in [go_lib::run].

The macro rewrites

โ“˜
#[go_lib::run]
fn main() {
    /* body */
}

into

โ“˜
fn main() {
    go_lib::run(move || {
        /* body */
    })
}

When the function has a return type the closure is annotated with the same type so that ? and explicit return expressions work as expected:

โ“˜
#[go_lib::run]
fn main() -> Result<(), MyError> {
    do_work()?;
    Ok(())
}
// expands to:
fn main() -> Result<(), MyError> {
    go_lib::run(move || -> Result<(), MyError> {
        do_work()?;
        Ok(())
    })
}

Function parameters (if any) are captured by the move closure, so the macro also works on non-main entry points or helper functions.

ยงErrors

Emits a compile error if the function is async (go-lib provides its own concurrency model and does not interact with an async executor).