From 32fd918a43281aa332c6683e50d2649fbd9f8fa2 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Tue, 15 Aug 2023 20:18:11 +0200 Subject: [PATCH] Remove `Send` bound --- chorus-macros/src/lib.rs | 2 +- src/types/entities/mod.rs | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/chorus-macros/src/lib.rs b/chorus-macros/src/lib.rs index c5cc25c..72e5ddd 100644 --- a/chorus-macros/src/lib.rs +++ b/chorus-macros/src/lib.rs @@ -84,7 +84,7 @@ pub fn composite_derive(input: TokenStream) -> TokenStream { let ident = &input.ident; let expanded = quote! { - #[async_trait::async_trait] + #[async_trait::async_trait(?Send)] impl Composite for #ident { async fn watch_whole(self, gateway: &GatewayHandle) -> Self { Self { diff --git a/src/types/entities/mod.rs b/src/types/entities/mod.rs index 1331c9c..7f8cc56 100644 --- a/src/types/entities/mod.rs +++ b/src/types/entities/mod.rs @@ -50,15 +50,19 @@ mod user_settings; mod voice_state; mod webhook; -#[async_trait] +#[async_trait(?Send)] pub trait Composite { async fn watch_whole(self, gateway: &GatewayHandle) -> Self; async fn option_observe_fn( value: Option>>, gateway: &GatewayHandle, - ) -> Option>> { + ) -> Option>> + where + T: Composite, + { if let Some(value) = value { + let value = value.clone(); Some(gateway.observe_and_get(value).await) } else { None @@ -68,7 +72,10 @@ pub trait Composite { async fn option_vec_observe_fn( value: Option>>>, gateway: &GatewayHandle, - ) -> Option>>> { + ) -> Option>>> + where + T: Composite, + { if let Some(value) = value { let mut vec = Vec::new(); for component in value.into_iter() { @@ -80,14 +87,20 @@ pub trait Composite { } } - async fn value_observe_fn(value: Arc>, gateway: &GatewayHandle) -> Arc> { + async fn value_observe_fn(value: Arc>, gateway: &GatewayHandle) -> Arc> + where + T: Composite, + { gateway.observe_and_get(value).await } async fn vec_observe_fn( value: Vec>>, gateway: &GatewayHandle, - ) -> Vec>> { + ) -> Vec>> + where + T: Composite, + { let mut vec = Vec::new(); for component in value.into_iter() { vec.push(gateway.observe_and_get(component).await);