pub struct Context { /* private fields */ }
Expand description
A struct containing all of the ‘global’ state within the framework.
Implementations§
Source§impl Context
impl Context
Sourcepub fn run<S, F, E>(&mut self, init: F) -> Result<(), E>
pub fn run<S, F, E>(&mut self, init: F) -> Result<(), E>
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§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl !Send for Context
impl !Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more