use std::ops::Deref;
use futures::future::BoxFuture;
use crate::{
system::{AsyncSystem, DynamicSystemData, System},
world::World,
};
pub type ThreadRun = Box<dyn for<'a> Run<'a> + Send>;
pub type LocalRun = Box<dyn for<'a> Run<'a>>;
pub type ThreadRunAsync = Box<dyn for<'a> RunAsync<'a> + Send>;
pub type LocalRunAsync = Box<dyn for<'a> RunAsync<'a>>;
pub trait Run<'a> {
fn run(&mut self, world: &'a World);
}
impl<'a, T> Run<'a> for T
where
T: System<'a>,
{
fn run(&mut self, world: &'a World) {
let data = T::SystemData::fetch(self.accessor().deref(), world);
self.run(data)
}
}
pub trait RunAsync<'a> {
fn run(&mut self, world: &'a World) -> BoxFuture<'a, ()>;
}
impl<'a, T> RunAsync<'a> for T
where
T: AsyncSystem<'a>,
{
fn run(&mut self, world: &'a World) -> BoxFuture<'a, ()> {
let data = T::SystemData::fetch(self.accessor().deref(), world);
self.run_async(data)
}
}