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>(&mut self, state: &mut S) -> Resultwhere
S: State,
pub fn run<S>(&mut self, state: &mut S) -> Resultwhere
S: State,
Runs the game using the provided State
implementation.
Examples
struct GameState;
impl State for GameState { }
fn main() -> tetra::Result {
ContextBuilder::default().build()?.run(&mut GameState)
}
sourcepub fn run_with<S, F>(&mut self, init: F) -> Resultwhere
S: State,
F: FnOnce(&mut Context) -> Result<S>,
pub fn run_with<S, F>(&mut self, init: F) -> Resultwhere
S: State,
F: FnOnce(&mut Context) -> Result<S>,
Constructs an implementation of State
using the given closure, and then runs it.
This is mainly handy when chaining methods, as it allows you to call your State
constructor
without breaking the chain.
Examples
struct GameState {
texture: Texture,
}
impl GameState {
fn new(ctx: &mut Context) -> tetra::Result<GameState> {
Ok(GameState {
texture: Texture::new(ctx, "./examples/resources/player.png")?,
})
}
}
impl State for GameState { }
fn main() -> tetra::Result {
ContextBuilder::default().build()?.run_with(GameState::new)
}
Auto Trait Implementations§
impl RefUnwindSafe for Context
impl !Send for Context
impl !Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SetParameter for T
impl<T> SetParameter for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.