Trait dunge::Loop

source ·
pub trait Loop {
    type Error: From<Error> + Debug;

    // Required methods
    fn update(
        &mut self,
        context: &mut Context,
        input: &Input<'_>
    ) -> Result<(), Self::Error>;
    fn render(&self, frame: &mut Frame<'_>) -> Result<(), Self::Error>;

    // Provided methods
    fn error_occurred(&mut self, err: Self::Error) { ... }
    fn close_requested(&mut self) -> bool { ... }
}
Expand description

The main application loop.

Required Associated Types§

Required Methods§

source

fn update( &mut self, context: &mut Context, input: &Input<'_> ) -> Result<(), Self::Error>

Calls before render a frame to update the state.

It accepts the Context and an Input. The context uses to update the application state, create or delete any resources. The input contains an inputed data like a mouse position and etc.

Errors

Return Error if this fails.

source

fn render(&self, frame: &mut Frame<'_>) -> Result<(), Self::Error>

Calls on render a frame.

It accepts a Frame to draw something on the canvas.

Errors

Return Error if this fails.

Provided Methods§

source

fn error_occurred(&mut self, err: Self::Error)

Calls when an error has occurred.

source

fn close_requested(&mut self) -> bool

Calls when a close is requested.

Returns a flag whether to terminate the main loop or not.

Implementations on Foreign Types§

source§

impl<L> Loop for Box<L>where L: Loop,

§

type Error = <L as Loop>::Error

source§

fn update( &mut self, context: &mut Context, input: &Input<'_> ) -> Result<(), Self::Error>

source§

fn render(&self, frame: &mut Frame<'_>) -> Result<(), Self::Error>

source§

impl<L> Loop for &mut Lwhere L: Loop,

§

type Error = <L as Loop>::Error

source§

fn update( &mut self, context: &mut Context, input: &Input<'_> ) -> Result<(), Self::Error>

source§

fn render(&self, frame: &mut Frame<'_>) -> Result<(), Self::Error>

Implementors§