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