Skip to main content

SdlApp

Trait SdlApp 

Source
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§

Source

type Error: Debug

Custom error type returned on initialization failure.

Required Methods§

Source

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.

Source

fn iterate(&mut self) -> SDL_AppResult

Called repeatedly to process a single frame.

Source

fn event(&mut self, event: &SDL_Event) -> SDL_AppResult

Called when an event arrives.

Source

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.

Implementors§