use std::any::Any;
pub trait ErasedEventQueue {
fn as_any_mut(&mut self) -> &mut dyn Any;
}
#[derive(Default)]
pub struct EventQueue<E> {
events: Vec<E>,
}
impl<E> EventQueue<E> {
pub const fn new() -> Self {
let events = vec![];
Self { events }
}
pub fn new_box() -> Box<Self> {
let this = Self::new();
Box::new(this)
}
pub fn queue(&mut self, event: E) {
self.events.push(event);
}
pub fn drain(&mut self) -> impl Iterator<Item = E> {
self.events.drain(..)
}
}
impl<E> ErasedEventQueue for EventQueue<E>
where
E: 'static,
{
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}