pub struct Context { /* private fields */ }
Expand description

A struct containing all of the ‘global’ state within the framework.

Implementations

Runs the game.

The init parameter takes a function or closure that creates a State implementation. A common pattern is to use method references to pass in your state’s constructor directly - see the example below for how this works.

The error type returned by your init closure currently must match the error type returned by your State methods. This limitation may be lifted in the future.

Errors

If the State returns an error from update, draw or event, the game will stop running and this method will return the error.

Examples
use tetra::{Context, ContextBuilder, State};

struct GameState;

impl GameState {
    fn new(ctx: &mut Context) -> tetra::Result<GameState> {
        Ok(GameState)
    }
}

impl State for GameState { }

fn main() -> tetra::Result {
    // Because GameState::new takes `&mut Context` and returns a `State` implementation
    // wrapped in a `Result`, you can use it without a closure wrapper:
    ContextBuilder::new("Hello, world!", 1280, 720)
        .build()?
        .run(GameState::new)
}

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.