diff options
Diffstat (limited to 'src/seventv.rs')
| -rw-r--r-- | src/seventv.rs | 56 |
1 files changed, 28 insertions, 28 deletions
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)); - } -} |
