#loops #real-time #main

main_loop

main loop for real time applications

13 releases

Uses old Rust 2015

0.3.3 Nov 24, 2018
0.3.2 Jun 14, 2018
0.3.1 May 23, 2018
0.3.0 Mar 5, 2018
0.1.0 Nov 26, 2017

#6 in #main

42 downloads per month
Used in 3 crates

MIT license

9KB
192 lines

main_loop

main loop for real time applications

No Default features

main_loop = { version = "0.3", default-features = false }
extern crate main_loop;

use main_loop::ControlFlow;

fn main() {
    main_loop::run(|ms| {
        println!("{:?}ms since start", ms);
        ControlFlow::Continue
    });
}

glutin

main_loop = { version = "0.3" }
extern crate glutin;
extern crate main_loop;

use main_loop::ControlFlow;

fn main() {
    let mut events_loop = glutin::EventsLoop::new();
    let window = glutin::WindowBuilder::new()
        .with_title("Glutin")
        .with_dimensions(512, 512);
    let context = glutin::ContextBuilder::new();
    let _gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap();


    main_loop::glutin::run(&mut events_loop, |events, ms| {
        println!("{:?}ms since start", ms);

        for event in events {
            println!("{:?}", event);
        }

        ControlFlow::Continue
    });
}

winit

main_loop = { version = "0.3" }
extern crate main_loop;
extern crate winit;

use main_loop::ControlFlow;
use winit::{EventsLoop, Window};

fn main() {
    let mut events_loop = EventsLoop::new();
    let _window = Window::new(&events_loop).unwrap();

    main_loop::winit::run(&mut events_loop, |events, ms| {
        println!("{:?}ms since start", ms);

        for event in events {
            println!("{:?}", event);
        }

        ControlFlow::Continue
    });
}

Dependencies

~4–16MB
~242K SLoC