summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-09 02:11:48 +0500
committerilotterytea <iltsu@alright.party>2025-04-09 02:11:48 +0500
commit93e26506c0211a3ebefa958e1df0d8cfbfc12b03 (patch)
tree8c7f7801031f9e2dbce8c94b7b477454ca45d5e0
parentfec84cee486d5d4444b286c7d92610150043a1ea (diff)
upd: function signatures for RetrieveEmoteWS
-rw-r--r--src/betterttv.rs56
-rw-r--r--src/emotes.rs11
-rw-r--r--src/seventv.rs56
3 files changed, 63 insertions, 60 deletions
diff --git a/src/betterttv.rs b/src/betterttv.rs
index 07dae2c..2d8134b 100644
--- a/src/betterttv.rs
+++ b/src/betterttv.rs
@@ -94,17 +94,40 @@ impl RetrieveEmoteAPI<BetterTTVEmote> for BetterTTVAPIClient {
}
}
-pub struct BetterTTVWSClient {
+pub struct BetterTTVWSClient<F>
+where
+ F: Fn(String, Option<String>, Emote),
+{
url: String,
- on_emote_create: Option<Box<dyn Fn(String, Option<String>, Emote) + Send + Sync>>,
- on_emote_update: Option<Box<dyn Fn(String, Option<String>, Emote) + Send + Sync>>,
- on_emote_delete: Option<Box<dyn Fn(String, Option<String>, Emote) + Send + Sync>>,
+ on_emote_create: Option<F>,
+ on_emote_update: Option<F>,
+ on_emote_delete: Option<F>,
joined_channels: HashSet<usize>,
awaiting_channels: HashSet<usize>,
}
-impl BetterTTVWSClient {
+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);
+ }
+
+ fn on_emote_update(&mut self, func: F) {
+ self.on_emote_update = Some(func);
+ }
+
+ fn on_emote_delete(&mut self, func: F) {
+ self.on_emote_delete = Some(func);
+ }
+}
+
+impl<F> BetterTTVWSClient<F>
+where
+ F: Fn(String, Option<String>, Emote),
+{
pub async fn new() -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Self)> {
let url = "wss://sockets.betterttv.net/ws";
@@ -259,26 +282,3 @@ impl BetterTTVWSClient {
self.joined_channels.clear();
}
}
-
-impl RetrieveEmoteWS<Emote> for BetterTTVWSClient {
- fn on_emote_create(
- &mut self,
- func: &'static (dyn Fn(String, Option<String>, Emote) + Send + Sync),
- ) {
- self.on_emote_create = Some(Box::new(func));
- }
-
- fn on_emote_update(
- &mut self,
- func: &'static (dyn Fn(String, Option<String>, Emote) + Send + Sync),
- ) {
- self.on_emote_update = Some(Box::new(func));
- }
-
- fn on_emote_delete(
- &mut self,
- func: &'static (dyn Fn(String, Option<String>, Emote) + Send + Sync),
- ) {
- self.on_emote_delete = Some(Box::new(func));
- }
-}
diff --git a/src/emotes.rs b/src/emotes.rs
index 1fa932c..53fd5ad 100644
--- a/src/emotes.rs
+++ b/src/emotes.rs
@@ -33,8 +33,11 @@ pub trait RetrieveEmoteAPI<T> {
async fn get_global_emotes(&self) -> Result<Vec<T>, Error>;
}
-pub trait RetrieveEmoteWS<T> {
- fn on_emote_create(&mut self, func: &'static (dyn Fn(String, Option<String>, T) + Send + Sync));
- fn on_emote_update(&mut self, func: &'static (dyn Fn(String, Option<String>, T) + Send + Sync));
- fn on_emote_delete(&mut self, func: &'static (dyn Fn(String, Option<String>, T) + Send + Sync));
+pub trait RetrieveEmoteWS<T, F>
+where
+ F: Fn(String, Option<String>, T),
+{
+ fn on_emote_create(&mut self, func: F);
+ fn on_emote_update(&mut self, func: F);
+ fn on_emote_delete(&mut self, func: F);
}
diff --git a/src/seventv.rs b/src/seventv.rs
index dd4a939..fd44aeb 100644
--- a/src/seventv.rs
+++ b/src/seventv.rs
@@ -193,11 +193,14 @@ impl RetrieveEmoteAPI<Emote> for SevenTVAPIClient {
}
}
-pub struct SevenTVWSClient {
+pub struct SevenTVWSClient<F>
+where
+ F: Fn(String, Option<String>, Emote),
+{
url: String,
- on_emote_create: Option<Box<dyn Fn(String, Option<String>, Emote) + Send + Sync>>,
- on_emote_update: Option<Box<dyn Fn(String, Option<String>, Emote) + Send + Sync>>,
- on_emote_delete: Option<Box<dyn Fn(String, Option<String>, Emote) + Send + Sync>>,
+ on_emote_create: Option<F>,
+ on_emote_update: Option<F>,
+ on_emote_delete: Option<F>,
joined_channels: HashSet<String>,
awaiting_channels: HashSet<String>,
@@ -205,7 +208,27 @@ pub struct SevenTVWSClient {
identified: bool,
}
-impl SevenTVWSClient {
+impl<F> RetrieveEmoteWS<Emote, F> for SevenTVWSClient<F>
+where
+ F: Fn(String, Option<String>, Emote),
+{
+ fn on_emote_create(&mut self, func: F) {
+ self.on_emote_create = Some(func);
+ }
+
+ fn on_emote_update(&mut self, func: F) {
+ self.on_emote_update = Some(func);
+ }
+
+ fn on_emote_delete(&mut self, func: F) {
+ self.on_emote_delete = Some(func);
+ }
+}
+
+impl<F> SevenTVWSClient<F>
+where
+ F: Fn(String, Option<String>, Emote),
+{
pub async fn new() -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Self)> {
let url = "wss://events.7tv.io/v3";
@@ -415,26 +438,3 @@ impl SevenTVWSClient {
self.joined_channels.clear();
}
}
-
-impl RetrieveEmoteWS<Emote> for SevenTVWSClient {
- fn on_emote_create(
- &mut self,
- func: &'static (dyn Fn(String, Option<String>, Emote) + Send + Sync),
- ) {
- self.on_emote_create = Some(Box::new(func));
- }
-
- fn on_emote_update(
- &mut self,
- func: &'static (dyn Fn(String, Option<String>, Emote) + Send + Sync),
- ) {
- self.on_emote_update = Some(Box::new(func));
- }
-
- fn on_emote_delete(
- &mut self,
- func: &'static (dyn Fn(String, Option<String>, Emote) + Send + Sync),
- ) {
- self.on_emote_delete = Some(Box::new(func));
- }
-}