diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-09 02:36:05 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-09 02:36:05 +0500 |
| commit | a4ce687ddd119ff97ac1efd3b23d0c27013845f4 (patch) | |
| tree | beb652ec216f425ab18bddb0efcfa2fd088c115e /src/betterttv.rs | |
| parent | 93e26506c0211a3ebefa958e1df0d8cfbfc12b03 (diff) | |
upd: function signatures for RetrieveEmoteWS (attempt 2)
Diffstat (limited to 'src/betterttv.rs')
| -rw-r--r-- | src/betterttv.rs | 46 |
1 files changed, 23 insertions, 23 deletions
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<BetterTTVEmote> for BetterTTVAPIClient { } } -pub struct BetterTTVWSClient<F> -where - F: Fn(String, Option<String>, Emote), -{ +pub struct BetterTTVWSClient { url: String, - on_emote_create: Option<F>, - on_emote_update: Option<F>, - on_emote_delete: Option<F>, + on_emote_create: Option<RetrieveEmoteHandler<Emote>>, + on_emote_update: Option<RetrieveEmoteHandler<Emote>>, + on_emote_delete: Option<RetrieveEmoteHandler<Emote>>, joined_channels: HashSet<usize>, awaiting_channels: HashSet<usize>, } -impl<F> RetrieveEmoteWS<Emote, F> for BetterTTVWSClient<F> -where - F: Fn(String, Option<String>, Emote), -{ - fn on_emote_create(&mut self, func: F) { - self.on_emote_create = Some(func); +impl RetrieveEmoteWS<Emote> for BetterTTVWSClient { + fn on_emote_create( + &mut self, + func: impl Fn(String, Option<String>, 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<String>, 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<String>, Emote) + Send + Sync + 'static, + ) { + self.on_emote_delete = Some(Arc::new(func)); } } -impl<F> BetterTTVWSClient<F> -where - F: Fn(String, Option<String>, Emote), -{ +impl BetterTTVWSClient { pub async fn new() -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Self)> { let url = "wss://sockets.betterttv.net/ws"; |
