wiggle::async_trait is defined as async_trait::async_trait(?Send)

async methods used by wiggle currently need to Not have the Send
constraint, so rather than make all use sites pass the argument
to the re-exported async_trait macro, define a new macro that
applies the argument.
This commit is contained in:
Pat Hickey
2021-03-29 10:04:42 -07:00
parent b1a3c9047f
commit e38166ac3f
7 changed files with 25 additions and 10 deletions

View File

@@ -83,11 +83,12 @@ use syn::parse_macro_input;
///
/// /// The above witx text contains one module called `$example`. So, we must
/// /// implement this one method trait for our ctx type.
/// #[wiggle::async_trait(?Send)]
/// #[wiggle::async_trait]
/// /// We specified in the `async_` field that `example::double_int_return_float`
/// /// is an asynchronous method. Therefore, we use the `async_trait` proc macro
/// /// (re-exported by wiggle from the crate of the same name) to define this
/// /// trait, so that `double_int_return_float` can be an `async fn`.
/// /// to define this trait, so that `double_int_return_float` can be an `async fn`.
/// /// `wiggle::async_trait` is defined as `#[async_trait::async_trait(?Send)]` -
/// /// in wiggle, async methods do not have the Send constaint.
/// impl example::Example for YourCtxType {
/// /// The arrays module has two methods, shown here.
/// /// Note that the `GuestPtr` type comes from `wiggle`,
@@ -156,3 +157,13 @@ pub fn from_witx(args: TokenStream) -> TokenStream {
TokenStream::from(quote! { #code #metadata })
}
#[proc_macro_attribute]
pub fn async_trait(attr: TokenStream, item: TokenStream) -> TokenStream {
let _ = parse_macro_input!(attr as syn::parse::Nothing);
let item = proc_macro2::TokenStream::from(item);
TokenStream::from(quote! {
#[wiggle::async_trait_crate::async_trait(?Send)]
#item
})
}