Winter maybe-async
This crate contains the maybe_async procedural attribute macro and the maybe_await procedural macro which abstract away Rust sync/async.
maybe_async
The maybe_async macro will conditionally add the async keyword to a function it marks depending on the async feature being enabled. To generate the asynchronous version, enable the async feature on the crate. If the async feature is off, the synchronous version will be generated. For example,
// Adding `maybe_async` to trait functions
// Adding `maybe_async` to regular functions
When the async feature is enabled, the above code will be transformed into:
async
maybe_await
To complement maybe_async we also have the maybe_await procedural macro that conditionally adds the .await keyword to the end of an expression depending on the async feature flag.
When the async feature is enabled, the above code will be transformed into:
async
async
maybe_async_trait
The maybe_async_trait macro can be applied to traits, and it will conditionally add the async keyword to trait methods annotated with #[maybe_async], depending on the async feature being enabled. It also applies #[async_trait::async_trait(?Send)] to the trait or impl block when the async feature is on.
For example:
// Adding `maybe_async_trait` to a trait definition
// Adding `maybe_async_trait` to an implementation of the trait
When async is set, it gets transformed into:
License
This project is MIT licensed.