summaryrefslogtreecommitdiff
path: root/src/seventv.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/seventv.rs')
-rw-r--r--src/seventv.rs46
1 files changed, 23 insertions, 23 deletions
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<Emote> for SevenTVAPIClient {
}
}
-pub struct SevenTVWSClient<F>
-where
- F: Fn(String, Option<String>, Emote),
-{
+pub struct SevenTVWSClient {
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<String>,
awaiting_channels: HashSet<String>,
@@ -208,27 +205,30 @@ where
identified: bool,
}
-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);
+impl RetrieveEmoteWS<Emote> for SevenTVWSClient {
+ 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> SevenTVWSClient<F>
-where
- F: Fn(String, Option<String>, Emote),
-{
+impl SevenTVWSClient {
pub async fn new() -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Self)> {
let url = "wss://events.7tv.io/v3";