Skip to content

Commit 9b066de

Browse files
committed
f Drop trait support for maybe_async
1 parent eda480b commit 9b066de

File tree

1 file changed

+4
-57
lines changed

1 file changed

+4
-57
lines changed

lightning-macros/src/lib.rs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,7 @@
2121
use proc_macro::TokenStream;
2222
use quote::quote;
2323
use syn::spanned::Spanned;
24-
use syn::{parse, ImplItemFn, ItemImpl, ItemTrait, Token};
25-
26-
fn add_async_trait(mut parsed: ItemTrait) -> TokenStream {
27-
let output = quote! {
28-
#[cfg(not(feature = "async-interface"))]
29-
#parsed
30-
};
31-
32-
for mut item in &mut parsed.items {
33-
if let syn::TraitItem::Fn(f) = &mut item {
34-
f.sig.asyncness = Some(Token![async](f.span()));
35-
}
36-
}
37-
38-
let output = quote! {
39-
#output
40-
41-
#[cfg(feature = "async-interface")]
42-
#[async_trait(?Send)]
43-
#parsed
44-
};
45-
46-
output.into()
47-
}
24+
use syn::{parse, ImplItemFn, Token};
4825

4926
fn add_async_method(mut parsed: ImplItemFn) -> TokenStream {
5027
let output = quote! {
@@ -64,44 +41,14 @@ fn add_async_method(mut parsed: ImplItemFn) -> TokenStream {
6441
output.into()
6542
}
6643

67-
fn add_async_impl_trait(mut parsed: ItemImpl) -> TokenStream {
68-
let output = quote! {
69-
#[cfg(not(feature = "async-interface"))]
70-
#parsed
71-
};
72-
73-
for mut item in &mut parsed.items {
74-
if let syn::ImplItem::Fn(f) = &mut item {
75-
f.sig.asyncness = Some(Token![async](f.span()));
76-
}
77-
}
78-
79-
let output = quote! {
80-
#output
81-
82-
#[cfg(feature = "async-interface")]
83-
#[async_trait(?Send)]
84-
#parsed
85-
};
86-
87-
output.into()
88-
}
89-
90-
/// Makes a method or every method of a trait `async`, if the `async-interface` feature is enabled.
91-
///
92-
/// Requires the `async-trait` crate as a dependency whenever this attribute is used on a trait
93-
/// definition or trait implementation.
44+
/// Makes a method `async`, if the `async-interface` feature is enabled.
9445
#[proc_macro_attribute]
9546
pub fn maybe_async(_attr: TokenStream, item: TokenStream) -> TokenStream {
96-
if let Ok(parsed) = parse(item.clone()) {
97-
add_async_trait(parsed)
98-
} else if let Ok(parsed) = parse(item.clone()) {
47+
if let Ok(parsed) = parse(item) {
9948
add_async_method(parsed)
100-
} else if let Ok(parsed) = parse(item) {
101-
add_async_impl_trait(parsed)
10249
} else {
10350
(quote! {
104-
compile_error!("#[maybe_async] can only be used on methods, trait or trait impl blocks")
51+
compile_error!("#[maybe_async] can only be used on methods")
10552
})
10653
.into()
10754
}

0 commit comments

Comments
 (0)