From a4ce687ddd119ff97ac1efd3b23d0c27013845f4 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 9 Apr 2025 02:36:05 +0500 Subject: upd: function signatures for RetrieveEmoteWS (attempt 2) --- src/seventv.rs | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/seventv.rs') diff --git a/src/seventv.rs b/src/seventv.rs index fd44aeb..e2b42ab 100644 --- a/src/seventv.rs +++ b/src/seventv.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::{collections::HashSet, sync::Arc}; use futures::SinkExt; use reqwest::{Client, Error}; @@ -10,7 +10,7 @@ use tokio_tungstenite::{ }; use tungstenite::{Message, Result, protocol::WebSocketConfig}; -use crate::emotes::{Emote, RetrieveEmoteAPI, RetrieveEmoteWS}; +use crate::emotes::{Emote, RetrieveEmoteAPI, RetrieveEmoteHandler, RetrieveEmoteWS}; #[derive(Deserialize, Serialize, Clone, Debug)] pub struct User { @@ -193,14 +193,11 @@ impl RetrieveEmoteAPI for SevenTVAPIClient { } } -pub struct SevenTVWSClient -where - F: Fn(String, Option, Emote), -{ +pub struct SevenTVWSClient { url: String, - on_emote_create: Option, - on_emote_update: Option, - on_emote_delete: Option, + on_emote_create: Option>, + on_emote_update: Option>, + on_emote_delete: Option>, joined_channels: HashSet, awaiting_channels: HashSet, @@ -208,27 +205,30 @@ where identified: bool, } -impl RetrieveEmoteWS for SevenTVWSClient -where - F: Fn(String, Option, Emote), -{ - fn on_emote_create(&mut self, func: F) { - self.on_emote_create = Some(func); +impl RetrieveEmoteWS for SevenTVWSClient { + fn on_emote_create( + &mut self, + func: impl Fn(String, Option, Emote) + Send + Sync + 'static, + ) { + self.on_emote_create = Some(Arc::new(func)); } - fn on_emote_update(&mut self, func: F) { - self.on_emote_update = Some(func); + fn on_emote_update( + &mut self, + func: impl Fn(String, Option, Emote) + Send + Sync + 'static, + ) { + self.on_emote_update = Some(Arc::new(func)); } - fn on_emote_delete(&mut self, func: F) { - self.on_emote_delete = Some(func); + fn on_emote_delete( + &mut self, + func: impl Fn(String, Option, Emote) + Send + Sync + 'static, + ) { + self.on_emote_delete = Some(Arc::new(func)); } } -impl SevenTVWSClient -where - F: Fn(String, Option, Emote), -{ +impl SevenTVWSClient { pub async fn new() -> Result<(WebSocketStream>, Self)> { let url = "wss://events.7tv.io/v3"; -- cgit v1.2.3