#applications #winit #lazy-evaluation #lazily #state #initializing #dealing

lazy_winit

A simple library for initializing winit application state lazily without dealing with nullables

2 releases

0.1.1 Feb 5, 2025
0.1.0 Jan 30, 2025

#3 in #lazily

Download history 111/week @ 2025-01-28 150/week @ 2025-02-04

261 downloads per month

Custom license

16KB
135 lines

lazy_winit

A simple library for initializing winit application state lazily without dealing with nullables.

fn main() -> Result<(), EventLoopError> {
    use lazy_winit::EventLoopExt;
    
    // This will run your application lazy, and will not check if it is initialized before being called. This may be
    // helpful for performance reasons, but may not be desirable on certain platforms.
    EventLoop::new()?.run_lazy_app_unchecked::<App>("Window Title".to_owned());
        
    // This will run your application lazily, and ensure that is initialized before being called.
    EventLoop::new()?.run_lazy_app::<App>("Window Title".to_owned());
}

struct App { window: Window }

impl lazy_winit::ApplicationInit for App {
    type State = String;
    
    fn new(event_loop: &ActiveEventLoop, title: Self::State) -> Self {
        let attributes: WindowAttributes = WindowAttributes::default()
            .with_title(title);
        let window: Window = event_loop.create_window(attributes).unwrap();

        Self { window }
    }
}

impl ApplicationHandler for App {
    // ...
}

Dependencies

~3–16MB
~239K SLoC