pkecs 9.0.0

Another ECS implementation.
Documentation
//! Contains types for storing consumable events.

use std::any::Any;

/// A type-erased event queue.
pub trait ErasedEventQueue {
    fn as_any_mut(&mut self) -> &mut dyn Any;
}

/// A FILO event queue.
#[derive(Default)]
pub struct EventQueue<E> {
    events: Vec<E>,
}

impl<E> EventQueue<E> {
    /// Initializes a new, empty instance of [`self`].
    pub const fn new() -> Self {
        let events = vec![];

        Self { events }
    }

    /// Initializes [`self`] on the heap.
    pub fn new_box() -> Box<Self> {
        let this = Self::new();

        Box::new(this)
    }

    /// Pushes an event onto [`self`].
    pub fn queue(&mut self, event: E) {
        self.events.push(event);
    }

    /// Drains all events from [`self`].
    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
    }
}