pub trait SdlApp: Sized + Send {
type Error: Debug;
// Required methods
fn init() -> Result<Self, Self::Error>;
fn iterate(&mut self) -> SDL_AppResult;
fn event(&mut self, event: &SDL_Event) -> SDL_AppResult;
fn quit(&mut self, result: SDL_AppResult);
}Expand description
Idiomatic Rust trait for SDL’s callback-based application loop.
§Thread Safety
Send is required because the app state is passed across the FFI boundary
and SDL may invoke callbacks from a thread it manages internally.
Required Associated Types§
Required Methods§
Sourcefn init() -> Result<Self, Self::Error>
fn init() -> Result<Self, Self::Error>
Called once at startup. Return Ok(Self) to continue, or Err to terminate.
§Memory Management
The returned Self instance is moved onto the heap and its ownership
is handed to SDL. It will be passed back to iterate, event, and quit.
Sourcefn iterate(&mut self) -> SDL_AppResult
fn iterate(&mut self) -> SDL_AppResult
Called repeatedly to process a single frame.
Sourcefn event(&mut self, event: &SDL_Event) -> SDL_AppResult
fn event(&mut self, event: &SDL_Event) -> SDL_AppResult
Called when an event arrives.
Sourcefn quit(&mut self, result: SDL_AppResult)
fn quit(&mut self, result: SDL_AppResult)
Called before the app exits.
After this method returns, the app state is automatically dropped and freed.
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.