Make trait Debug

This commit is contained in:
bitfl0wer 2023-08-16 21:26:27 +02:00
parent fbf72b74d0
commit 887ba4a1b1
10 changed files with 22 additions and 7 deletions

View File

@ -104,7 +104,7 @@ pub fn composite_derive(input: TokenStream) -> TokenStream {
let ident = &input.ident; let ident = &input.ident;
let expanded = quote! { let expanded = quote! {
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl<T: Updateable + Clone> Composite<T> for #ident { impl<T: Updateable + Clone + Debug> Composite<T> for #ident {
async fn watch_whole(self, gateway: &GatewayHandle) -> Self { async fn watch_whole(self, gateway: &GatewayHandle) -> Self {
Self { Self {
#(#field_exprs,)* #(#field_exprs,)*

View File

@ -5,6 +5,7 @@ use chrono::Utc;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_string_from_number; use serde_aux::prelude::deserialize_string_from_number;
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use std::fmt::Debug;
use crate::gateway::{GatewayHandle, Updateable}; use crate::gateway::{GatewayHandle, Updateable};
use crate::types::{ use crate::types::{

View File

@ -1,3 +1,4 @@
use std::fmt::Debug;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use chorus_macros::{Composite, Updateable}; use chorus_macros::{Composite, Updateable};

View File

@ -1,3 +1,4 @@
use std::fmt::Debug;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use chorus_macros::{observe_option_vec, observe_vec, Composite, Updateable}; use chorus_macros::{observe_option_vec, observe_vec, Composite, Updateable};

View File

@ -24,6 +24,7 @@ pub use webhook::*;
use crate::gateway::{GatewayHandle, Updateable}; use crate::gateway::{GatewayHandle, Updateable};
use async_trait::async_trait; use async_trait::async_trait;
use std::fmt::Debug;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
mod application; mod application;
@ -51,7 +52,7 @@ mod voice_state;
mod webhook; mod webhook;
#[async_trait(?Send)] #[async_trait(?Send)]
pub trait Composite<T: Updateable + Clone> { pub trait Composite<T: Updateable + Clone + Debug> {
async fn watch_whole(self, gateway: &GatewayHandle) -> Self; async fn watch_whole(self, gateway: &GatewayHandle) -> Self;
async fn option_observe_fn( async fn option_observe_fn(
@ -59,11 +60,12 @@ pub trait Composite<T: Updateable + Clone> {
gateway: &GatewayHandle, gateway: &GatewayHandle,
) -> Option<Arc<RwLock<T>>> ) -> Option<Arc<RwLock<T>>>
where where
T: Composite<T>, T: Composite<T> + Debug,
{ {
println!("Processed option value.");
if let Some(value) = value { if let Some(value) = value {
let value = value.clone(); let value = value.clone();
Some(gateway.observe_and_get(value).await) Some(gateway.observe(value).await)
} else { } else {
None None
} }
@ -76,10 +78,11 @@ pub trait Composite<T: Updateable + Clone> {
where where
T: Composite<T>, T: Composite<T>,
{ {
println!("Processed option vec value.");
if let Some(value) = value { if let Some(value) = value {
let mut vec = Vec::new(); let mut vec = Vec::new();
for component in value.into_iter() { for component in value.into_iter() {
vec.push(gateway.observe_and_get(component).await); vec.push(gateway.observe(component).await);
} }
Some(vec) Some(vec)
} else { } else {
@ -91,7 +94,8 @@ pub trait Composite<T: Updateable + Clone> {
where where
T: Composite<T>, T: Composite<T>,
{ {
gateway.observe_and_get(value).await println!("Processed value.");
gateway.observe(value).await
} }
async fn vec_observe_fn( async fn vec_observe_fn(
@ -101,9 +105,10 @@ pub trait Composite<T: Updateable + Clone> {
where where
T: Composite<T>, T: Composite<T>,
{ {
println!("Processed vec value.");
let mut vec = Vec::new(); let mut vec = Vec::new();
for component in value.into_iter() { for component in value.into_iter() {
vec.push(gateway.observe_and_get(component).await); vec.push(gateway.observe(component).await);
} }
vec vec
} }

View File

@ -2,6 +2,7 @@ use bitflags::bitflags;
use chorus_macros::{Composite, Updateable}; use chorus_macros::{Composite, Updateable};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_aux::prelude::{deserialize_option_number_from_string, deserialize_string_from_number}; use serde_aux::prelude::{deserialize_option_number_from_string, deserialize_string_from_number};
use std::fmt::Debug;
use crate::gateway::{GatewayHandle, Updateable}; use crate::gateway::{GatewayHandle, Updateable};
use crate::types::{utils::Snowflake, Composite}; use crate::types::{utils::Snowflake, Composite};

View File

@ -2,6 +2,7 @@ use chorus_macros::{Composite, Updateable};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_option_number_from_string; use serde_aux::prelude::deserialize_option_number_from_string;
use std::fmt::Debug;
use crate::gateway::{GatewayHandle, Updateable}; use crate::gateway::{GatewayHandle, Updateable};
use crate::types::{utils::Snowflake, Composite}; use crate::types::{utils::Snowflake, Composite};

View File

@ -3,6 +3,7 @@ use std::sync::{Arc, RwLock};
use chorus_macros::{Composite, Updateable}; use chorus_macros::{Composite, Updateable};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use crate::gateway::{GatewayHandle, Updateable}; use crate::gateway::{GatewayHandle, Updateable};
use crate::types::{ use crate::types::{

View File

@ -1,3 +1,4 @@
use std::fmt::Debug;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use chorus_macros::{Composite, Updateable}; use chorus_macros::{Composite, Updateable};

View File

@ -42,6 +42,9 @@ impl UpdateMessage<Channel> for ChannelUpdate {
fn update(&mut self, object_to_update: Arc<RwLock<Channel>>) { fn update(&mut self, object_to_update: Arc<RwLock<Channel>>) {
let mut write = object_to_update.write().unwrap(); let mut write = object_to_update.write().unwrap();
*write = self.channel.clone(); *write = self.channel.clone();
drop(write);
println!("{:?}", self.channel.name);
assert_eq!(self.channel.name, object_to_update.read().unwrap().name);
} }
fn id(&self) -> Snowflake { fn id(&self) -> Snowflake {
self.channel.id self.channel.id