1
0
Fork
You've already forked asyncator
0
Save code duplication when writing very similar sync and async functions.
  • Rust 100%
2026年06月01日 09:31:55 +02:00
src fix: panic if >3 pre-attributes 2026年05月31日 08:09:04 +02:00
tests feat: first version 2026年05月14日 23:19:02 +02:00
.gitignore feat: first version 2026年05月14日 23:19:02 +02:00
Cargo.lock feat: first version 2026年05月14日 23:19:02 +02:00
Cargo.toml feat: first version 2026年05月14日 23:19:02 +02:00
LICENSE chore: add license 2026年06月01日 09:31:55 +02:00
README.md doc: added similar crates 2026年05月31日 08:08:35 +02:00
TODO.md chore: add license 2026年06月01日 09:31:55 +02:00

Excerpts from the crate's documentation

Save code duplication when writing very similar sync and async functions. This is all done via the [asyncator] macro.

Examples

useasyncator::asyncator;#[asyncator]#[name_sync(function_sync)]asyncfn function_async()-> &'static str {#[cfg_sync]return"Hello world";#[cfg_async]async{"Hello world"}.await}

expands to

fn function_sync()-> &'static str {return"Hello world";}asyncfn function_async()-> &'static str {async{"Hello world"}.await}

Usage to gate a blocking API behind a feature

useasyncator::asyncator;#[asyncator]#[name_sync(my_function_blocking)]#[cfg_sync(feature = "blocking")]// So it's always included
#[cfg_async(true)]fn my_function(){}

More info in this crate documentation, but since I am not on crates.io there is no proper way to see it, save for cloning this repo and running cargo doc (or you can read the doc in the code)

As a result of not being on crates.io, if you want to add asyncator as a dependency, see the official doc

Similar crates: