pkecs 9.0.0

Another ECS implementation.
Documentation
//! Contains a system scheduler.

pub mod handler;
pub mod param;
pub mod schedule;

use std::{any::TypeId, collections::HashMap};
use super::world::UnsafeWorldCell;
use handler::{into::IntoSystemHandler, SystemHandler};

/// Stores and schedules systems.
#[derive(Default)]
pub struct Systems {
    systems: HashMap<TypeId, Vec<Box<dyn SystemHandler>>>,
}

impl Systems {
    /// Registers a [`System`] to run at the specified schedule.
    pub fn add<S, H, P>(&mut self, _: S, handler: H)
        where
            S: 'static,
            H: IntoSystemHandler<P> + 'static,
            P: 'static,
    {
        let id = TypeId::of::<S>();

        self.systems
            .entry(id)
            .or_insert(vec![])
            .push(Box::new(handler.into_handler()));
    }

    /// Runs all systems under the specified schedule.
    pub fn run<S>(&self, _: S, cell: &UnsafeWorldCell)
        where
            S: 'static,
    {
        let id = TypeId::of::<S>();

        self.systems
            .get(&id)
            .map(|s| s.iter().for_each(|s| s.run(cell)));
    }
}