cgp_async_macro/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*!
   This library provides helper macros for using async functions in traits.
*/

extern crate proc_macro;

use proc_macro::TokenStream;

mod impl_async;
mod strip_async;

/**
   This macro can be used in place of the [`macro@native_async`] macro
   to strip away all use of `async` and `.await` syntax. This helps emulate
   async-generic by turnining async functions into sync functions.
*/
#[proc_macro_attribute]
pub fn strip_async(_attr: TokenStream, stream: TokenStream) -> TokenStream {
    strip_async::strip_async(stream.into()).into()
}

#[proc_macro_attribute]
pub fn native_async(_attr: TokenStream, stream: TokenStream) -> TokenStream {
    impl_async::impl_async(stream.into()).into()
}