Skip to main content

run

Macro run 

Source
macro_rules! run {
    ($setup:expr, $($update:expr),+ $(,)?) => { ... };
}
Expand description

Runs a program from a setup expression and one or more per-frame update expressions, the variadic form of run. Setup runs once and returns your state; each update runs every frame, in the order given, and receives that state. Returns the same Result as run, so main can return it.

fn main() -> Result<(), Box<dyn std::error::Error>> {
    run!(
        |world| spawn_cube(world, vec3(0.0, 0.5, 0.0)),
        |world, cube| rotate(world, *cube, Vec3::y(), delta_time(world)),
    )
}

Each update is a fn(&mut World, &mut Data) or a non-capturing closure of that shape, where Data is whatever setup returns. They all see the same state, so a program splits cleanly into named systems:

run!(setup, handle_input, move_player, check_collisions)

For a static scene with no per-frame work, use run_scene instead.