maybe_async

Attribute Macro maybe_async 

Source
#[maybe_async]
Expand description

Parses a function (regular or trait) and conditionally adds the async keyword depending on the async feature flag being enabled.

For example:

trait ExampleTrait {
    #[maybe_async]
    fn say_hello(&self);

    #[maybe_async]
    fn get_hello(&self) -> String;
}


#[maybe_async]
fn hello_world() {
    // ...
}

When the async feature is enabled, will be transformed into:

trait ExampleTrait {
    async fn say_hello(&self);

    async fn get_hello(&self) -> String;
}


async fn hello_world() {
    // ...
}