Trait Game

Source
pub trait Game: Sized {
    // Required methods
    fn create(engine: &mut Engine) -> Result<Self, Box<dyn Error>>;
    fn update(&mut self, engine: &mut Engine) -> Result<bool, Box<dyn Error>>;

    // Provided method
    fn receive_input(&mut self, _engine: &mut Engine, _input: String) { ... }
}
Expand description

This is the core of the Game ran by the Engine

Required Methods§

Source

fn create(engine: &mut Engine) -> Result<Self, Box<dyn Error>>

Create the Game instance

§Errors

This is allowed to return an error. It will be printed in the console with either debug formatting in debug builds (debug_assertions enabled) and display in release builds

If you use a closure as the game type this will always return an error

Source

fn update(&mut self, engine: &mut Engine) -> Result<bool, Box<dyn Error>>

This is the core loop of the engine. It will be called every time the games needs a redraw.

§Returns

The return value of the function will determine if the game needs to be shut down or not. Returning Ok(true) will continue to the next frame Ok(false) will gracefully shut down the program Err(_) will print out the error onto stderr and stop the program

Provided Methods§

Source

fn receive_input(&mut self, _engine: &mut Engine, _input: String)

This function will be called when the input mode finishes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F: FnMut(&mut Engine) -> Result<bool, Box<dyn Error>> + 'static> Game for F