async_ecs/dispatcher/
run.rs1use std::ops::Deref;
2
3use futures::future::BoxFuture;
4
5use crate::{
6 system::{AsyncSystem, DynamicSystemData, System},
7 world::World,
8};
9
10pub type ThreadRun = Box<dyn for<'a> Run<'a> + Send>;
11pub type LocalRun = Box<dyn for<'a> Run<'a>>;
12
13pub type ThreadRunAsync = Box<dyn for<'a> RunAsync<'a> + Send>;
14pub type LocalRunAsync = Box<dyn for<'a> RunAsync<'a>>;
15
16pub trait Run<'a> {
19 fn run(&mut self, world: &'a World);
28}
29
30impl<'a, T> Run<'a> for T
31where
32 T: System<'a>,
33{
34 fn run(&mut self, world: &'a World) {
35 let data = T::SystemData::fetch(self.accessor().deref(), world);
36
37 self.run(data)
38 }
39}
40
41pub trait RunAsync<'a> {
44 fn run(&mut self, world: &'a World) -> BoxFuture<'a, ()>;
53}
54
55impl<'a, T> RunAsync<'a> for T
56where
57 T: AsyncSystem<'a>,
58{
59 fn run(&mut self, world: &'a World) -> BoxFuture<'a, ()> {
60 let data = T::SystemData::fetch(self.accessor().deref(), world);
61
62 self.run_async(data)
63 }
64}