unen_event 0.0.3

Event crate for UnnamedEngine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::any::Any;

pub trait Event: Any + Send + Sync {
    fn as_any(&self) -> &dyn Any;
}

pub struct EventBox(Box<dyn Event>);

impl EventBox {
    pub fn new<E: Event>(event: E) -> Self {
        Self(Box::new(event))
    }

    pub fn downcast_ref<E: Event>(&self) -> Option<&E> {
        self.0.as_any().downcast_ref::<E>()
    }
}