pub mod host;
pub use host::Host;
#[cfg(test)]
mod tests;
use std::future::Future;
pub use genawaiter;
use genawaiter::rc::Co;
pub struct Context<Game> where
Game : Play,
{
pub host : Host<Game>,
co : Co<Game::Event, Game::Input>,
}
impl<Game> Context<Game> where
Game : Play,
{
pub fn yield_default(&self) -> impl Future<Output = Game::Input> + '_ where
Game::Event : Default,
{
self.yield_event(Default::default())
}
pub fn yield_event(&self, mut event : Game::Event) -> impl Future<Output = Game::Input> + '_ {
self.host.process_event(&mut event);
self.co.yield_(event)
}
}
pub trait Play : Sized {
type Event : Sized;
type Input : Sized;
type Outcome : Sized;
fn play(ctx : Context<Self>) -> impl Future<Output = Self::Outcome>;
fn handle_event(&mut self, _event : &mut <Self as Play>::Event) { }
}