use std::time::Duration; use anyhow::Result; use flax::World; use super::events::Events; pub trait Module { fn on_update( &mut self, world: &mut World, events: &mut Events, frame_time: Duration, ) -> Result<()>; } pub struct ModulesStack { modules: Vec>, } impl ModulesStack { pub fn new() -> Self { Self { modules: Vec::new(), } } pub fn iter(&self) -> std::slice::Iter> { self.modules.iter() } pub fn iter_mut(&mut self) -> std::slice::IterMut> { self.modules.iter_mut() } pub fn push(&mut self, layer: T) { let layer = Box::new(layer); self.modules.push(layer); } pub fn insert(&mut self, index: usize, layer: T) { let layer = Box::new(layer); self.modules.insert(index, layer); } } impl Default for ModulesStack { fn default() -> Self { Self::new() } } impl<'a> IntoIterator for &'a ModulesStack { type Item = &'a Box; type IntoIter = std::slice::Iter<'a, Box>; fn into_iter(self) -> Self::IntoIter { self.iter() } } impl<'a> IntoIterator for &'a mut ModulesStack { type Item = &'a mut Box; type IntoIter = std::slice::IterMut<'a, Box>; fn into_iter(self) -> Self::IntoIter { self.iter_mut() } }