#[derive(Debug)]
struct Uncreatable;
impl std::fmt::Display for Uncreatable {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "The game was unable to be created")
}
}
impl std::error::Error for Uncreatable {}
pub trait Game: Sized {
fn create(engine: &mut crate::Engine) -> Result<Self, Box<dyn std::error::Error>>;
#[allow(clippy::missing_errors_doc)]
fn update(&mut self, engine: &mut crate::Engine) -> Result<bool, Box<dyn std::error::Error>>;
fn receive_input(&mut self, _engine: &mut crate::Engine, _input: String) {}
}
impl<F: (FnMut(&mut crate::Engine) -> Result<bool, Box<dyn std::error::Error>>) + 'static> Game
for F
{
fn create(_: &mut crate::Engine) -> Result<Self, Box<dyn std::error::Error>> {
Err(Uncreatable.into())
}
fn update(&mut self, engine: &mut crate::Engine) -> Result<bool, Box<dyn std::error::Error>> {
(self)(engine)
}
}