aerospike-macro 2.0.0

Aerospike Client for Rust Macros Crate. Not meant to be used independently.
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;

#[doc(hidden)]
#[proc_macro_attribute]
pub fn test(_attr: TokenStream, input: TokenStream) -> TokenStream {
    let input = syn::parse_macro_input!(input as syn::ItemFn);

    let ret = &input.sig.output;
    let name = &input.sig.ident;
    let body = &input.block;
    let attrs = &input.attrs;

    let result = if cfg!(feature = "rt-tokio") {
        quote! {
            #[test]
            #(#attrs)*
            fn #name() #ret {
                let _ = env_logger::try_init();

                // ::aerospike_rt::tokio::runtime::Runtime::new().unwrap().block_on( async {#body} )
                // Use a shared runtime for the tests and the client:
                crate::common::RUNTIME.block_on( async {#body} )
            }
        }
    } else if cfg!(feature = "rt-async-std") {
        quote! {
            #[test]
            #(#attrs)*
            fn #name() #ret {
                let _ = env_logger::try_init();

                // Runtime is already shared for async_std
                ::aerospike_rt::async_std::task::block_on( async {#body} )
            }
        }
    } else {
        panic!("No runtime selected!");
    };

    result.into()
}