Use async trait where needed

This commit is contained in:
bitfl0wer 2023-08-15 16:57:35 +02:00
parent ad508153e5
commit 28ea95f4a4
1 changed files with 8 additions and 14 deletions

View File

@ -58,27 +58,21 @@ pub fn composite_derive(input: TokenStream) -> TokenStream {
let observe = attrs.iter().any(|attr| attr.path().is_ident("observe")); let observe = attrs.iter().any(|attr| attr.path().is_ident("observe"));
let observe_vec = attrs.iter().any(|attr| attr.path().is_ident("observe_vec")); let observe_vec = attrs.iter().any(|attr| attr.path().is_ident("observe_vec"));
let field_is_arc_rwlock = if let syn::Type::Path(type_path) = &field.ty { let field_is_arc_rwlock = true;
type_path.path.segments.last().map_or(false, |segment| {
segment.ident == "Arc" || segment.ident == "RwLock"
})
} else {
false
};
if field_is_arc_rwlock { if field_is_arc_rwlock {
match (observe_option, observe_option_vec, observe, observe_vec) { match (observe_option, observe_option_vec, observe, observe_vec) {
(true, _, _, _) => quote! { (true, _, _, _) => quote! {
#field_name: option_observe_fn(self.#field_name) #field_name: Self::option_observe_fn(self.#field_name, gateway).await
}, },
(_, true, _, _) => quote! { (_, true, _, _) => quote! {
#field_name: option_vec_observe_fn(self.#field_name) #field_name: Self::option_vec_observe_fn(self.#field_name, gateway).await
}, },
(_, _, true, _) => quote! { (_, _, true, _) => quote! {
#field_name: value_observe_fn(self.#field_name) #field_name: Self::value_observe_fn(self.#field_name, gateway).await
}, },
(_, _, _, true) => quote! { (_, _, _, true) => quote! {
#field_name: vec_observe_fn(self.#field_name) #field_name: Self::vec_observe_fn(self.#field_name, gateway).await
}, },
_ => quote! { _ => quote! {
#field_name: self.#field_name #field_name: self.#field_name
@ -95,10 +89,10 @@ pub fn composite_derive(input: TokenStream) -> TokenStream {
let field_exprs = named.iter().map(process_field); let field_exprs = named.iter().map(process_field);
let ident = &input.ident; let ident = &input.ident;
let expanded = quote! { let expanded = quote! {
impl<T: Updateable> Composite<T> for #ident { #[async_trait::async_trait]
fn watch_whole(self) -> Self { impl<T: Updateable + Clone> Composite<T> for #ident {
async fn watch_whole(self, gateway: &GatewayHandle) -> Self {
Self { Self {
#(#field_exprs,)* #(#field_exprs,)*
} }