oxygengine_core/ecs/pipeline/engines/
closure.rs

1use crate::ecs::{
2    pipeline::{PipelineEngine, PipelineGraph},
3    Universe,
4};
5
6pub struct ClosurePipelineEngine {
7    closure: Box<dyn Fn(&mut Universe)>,
8}
9
10impl ClosurePipelineEngine {
11    pub fn new<F>(f: F) -> Self
12    where
13        F: Fn(&mut Universe) + 'static,
14    {
15        Self {
16            closure: Box::new(f),
17        }
18    }
19}
20
21impl PipelineEngine for ClosurePipelineEngine {
22    fn setup(&mut self, _: PipelineGraph) {}
23
24    fn run(&self, universe: &mut Universe) {
25        (self.closure)(universe);
26    }
27}
28
29impl<F> From<F> for ClosurePipelineEngine
30where
31    F: Fn(&mut Universe) + 'static,
32{
33    fn from(f: F) -> Self {
34        Self::new(f)
35    }
36}