1use std::{any::Any, fmt::Debug};
2
3use crate::{Event, Lock, Lockable, SendSync, Sendable, Shared};
4
5pub trait EventSender: Sendable + 'static {
10 fn send_event(&mut self, event: Event);
11}
12
13#[derive(Clone)]
15pub struct EventSink {
16 sender: Shared<Lock<dyn EventSender>>,
17}
18
19impl EventSink {
20 pub fn new(sender: impl EventSender) -> Self {
22 Self {
23 sender: Shared::new(Lock::new(sender)),
24 }
25 }
26
27 pub fn send(&self, event: impl Any + SendSync) {
29 self.sender.lock_mut().send_event(Event::new(event));
30 }
31}
32
33impl Debug for EventSink {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 f.debug_struct("EventSink").finish()
36 }
37}