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/betterttv.rs | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/betterttv.rs') diff --git a/src/betterttv.rs b/src/betterttv.rs index 2d8134b..0dbd4a3 100644 --- a/src/betterttv.rs +++ b/src/betterttv.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::{collections::HashSet, sync::Arc}; use futures::SinkExt; use reqwest::{Client, Error}; @@ -8,7 +8,7 @@ use tokio::net::TcpStream; use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async, tungstenite::Result}; use tungstenite::Message; -use crate::emotes::{Emote, EmoteBase, RetrieveEmoteAPI, RetrieveEmoteWS}; +use crate::emotes::{Emote, EmoteBase, RetrieveEmoteAPI, RetrieveEmoteHandler, RetrieveEmoteWS}; #[derive(Debug, Deserialize, Clone)] pub struct BetterTTVEmote { @@ -94,40 +94,40 @@ impl RetrieveEmoteAPI for BetterTTVAPIClient { } } -pub struct BetterTTVWSClient -where - F: Fn(String, Option, Emote), -{ +pub struct BetterTTVWSClient { 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, } -impl RetrieveEmoteWS for BetterTTVWSClient -where - F: Fn(String, Option, Emote), -{ - fn on_emote_create(&mut self, func: F) { - self.on_emote_create = Some(func); +impl RetrieveEmoteWS for BetterTTVWSClient { + 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 BetterTTVWSClient -where - F: Fn(String, Option, Emote), -{ +impl BetterTTVWSClient { pub async fn new() -> Result<(WebSocketStream>, Self)> { let url = "wss://sockets.betterttv.net/ws"; -- cgit v1.2.3