From 74958ecc6f5ee195d8fe214b3f66875fc6cefa99 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 12 Nov 2024 14:52:48 +0100 Subject: [PATCH] docs: add `fn main` to root examples This is not strictly required, but makes the examples a bit easier to read understand (especially since the `EventLoop` really _should_ be created inside `fn main`, and not in some random function potentially running on a random thread). --- src/lib.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 80a2388f..bda0a32b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,12 @@ //! //! ```no_run //! use winit::event_loop::EventLoop; -//! let event_loop = EventLoop::new().unwrap(); +//! +//! # // Intentionally use `fn main` for clarity +//! fn main() { +//! let event_loop = EventLoop::new().unwrap(); +//! // ... +//! } //! ``` //! //! Then you create a [`Window`] with [`create_window`]. @@ -83,19 +88,22 @@ //! } //! } //! -//! let event_loop = EventLoop::new().unwrap(); +//! # // Intentionally use `fn main` for clarity +//! fn main() { +//! let event_loop = EventLoop::new().unwrap(); //! -//! // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't -//! // dispatched any events. This is ideal for games and similar applications. -//! event_loop.set_control_flow(ControlFlow::Poll); +//! // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't +//! // dispatched any events. This is ideal for games and similar applications. +//! event_loop.set_control_flow(ControlFlow::Poll); //! -//! // ControlFlow::Wait pauses the event loop if no events are available to process. -//! // This is ideal for non-game applications that only update in response to user -//! // input, and uses significantly less power/CPU time than ControlFlow::Poll. -//! event_loop.set_control_flow(ControlFlow::Wait); +//! // ControlFlow::Wait pauses the event loop if no events are available to process. +//! // This is ideal for non-game applications that only update in response to user +//! // input, and uses significantly less power/CPU time than ControlFlow::Poll. +//! event_loop.set_control_flow(ControlFlow::Wait); //! -//! let mut app = App::default(); -//! event_loop.run_app(&mut app); +//! let mut app = App::default(); +//! event_loop.run_app(&mut app); +//! } //! ``` //! //! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be