use crate::imports::*;
pub type ApplicationEventsChannel = crate::runtime::channel::Channel<RuntimeEvent>;
#[derive(Clone, Debug)]
pub struct ApplicationEvent(Arc<dyn Any + Send + Sync>);
impl ApplicationEvent {
pub fn new<T>(event: T) -> Self
where
T: Any + Send + Sync + 'static,
{
ApplicationEvent(Arc::new(event))
}
#[allow(clippy::should_implement_trait)]
pub fn as_ref<T>(&self) -> &T
where
T: Any,
{
self.0.downcast_ref::<T>().unwrap()
}
pub fn as_arc<T>(self) -> Arc<T>
where
T: Any + Send + Sync,
{
self.0
.downcast::<T>()
.expect("unknown application event type")
}
}
#[derive(Clone, Debug)]
pub enum RuntimeEvent {
Error(String),
Exit,
VisibilityState(VisibilityState),
Application(ApplicationEvent),
}
impl RuntimeEvent {
pub fn new<T>(event: T) -> Self
where
T: Any + Send + Sync + 'static,
{
RuntimeEvent::Application(ApplicationEvent::new(event))
}
}