1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{
any::TypeId,
fmt::{Debug, Formatter, Result},
};
use super::event_type::EventType;
pub trait Event<T: EventType>: EventClone<T> {
fn is_guaranteed(&self) -> bool;
fn write(&self, out_bytes: &mut Vec<u8>);
fn get_typed_copy(&self) -> T;
fn get_type_id(&self) -> TypeId;
}
pub trait EventClone<T: EventType> {
fn clone_box(&self) -> Box<dyn Event<T>>;
}
impl<Z: EventType, T: 'static + Event<Z> + Clone> EventClone<Z> for T {
fn clone_box(&self) -> Box<dyn Event<Z>> {
Box::new(self.clone())
}
}
impl<T: EventType> Clone for Box<dyn Event<T>> {
fn clone(&self) -> Box<dyn Event<T>> {
EventClone::clone_box(self.as_ref())
}
}
impl<T: EventType> Debug for Box<dyn Event<T>> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.write_str("Boxed Event")
}
}