From 118c78a7c173d1f1bb77ad82165cc5cc417f6570 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sat, 22 Jun 2024 08:40:15 -0700 Subject: [PATCH] m: Clippy false positive The fn main is actually needed Signed-off-by: John Nunley --- README.md | 106 ++++++++++++++++++++++++++--------------------------- src/lib.rs | 1 + 2 files changed, 54 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index e538a33..3e39db6 100644 --- a/README.md +++ b/README.md @@ -69,62 +69,62 @@ use winit::event::{Event, WindowEvent}; use winit::event_loop::{ControlFlow, EventLoop}; use winit::window::Window; -include! { - "../examples/utils/winit_app.rs" -} - -let event_loop = EventLoop::new().unwrap(); - -let mut app = winit_app::WinitAppBuilder::with_init(|elwt| { - let window = { - let window = elwt.create_window(Window::default_attributes()); - Rc::new(window.unwrap()) - }; - let context = softbuffer::Context::new(window.clone()).unwrap(); - let surface = softbuffer::Surface::new(&context, window.clone()).unwrap(); - - (window, surface) -}).with_event_handler(|state, event, elwt| { - let (window, surface) = state; - elwt.set_control_flow(ControlFlow::Wait); - - match event { - Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } if window_id == window.id() => { - let (width, height) = { - let size = window.inner_size(); - (size.width, size.height) - }; - surface - .resize( - NonZeroU32::new(width).unwrap(), - NonZeroU32::new(height).unwrap(), - ) - .unwrap(); - - let mut buffer = surface.buffer_mut().unwrap(); - for index in 0..(width * height) { - let y = index / width; - let x = index % width; - let red = x % 255; - let green = y % 255; - let blue = (x * y) % 255; - - buffer[index as usize] = blue | (green << 8) | (red << 16); +include!("../examples/utils/winit_app.rs"); + +fn main() { + let event_loop = EventLoop::new().unwrap(); + + let mut app = winit_app::WinitAppBuilder::with_init(|elwt| { + let window = { + let window = elwt.create_window(Window::default_attributes()); + Rc::new(window.unwrap()) + }; + let context = softbuffer::Context::new(window.clone()).unwrap(); + let surface = softbuffer::Surface::new(&context, window.clone()).unwrap(); + + (window, surface) + }).with_event_handler(|state, event, elwt| { + let (window, surface) = state; + elwt.set_control_flow(ControlFlow::Wait); + + match event { + Event::WindowEvent { window_id, event: WindowEvent::RedrawRequested } if window_id == window.id() => { + let (width, height) = { + let size = window.inner_size(); + (size.width, size.height) + }; + surface + .resize( + NonZeroU32::new(width).unwrap(), + NonZeroU32::new(height).unwrap(), + ) + .unwrap(); + + let mut buffer = surface.buffer_mut().unwrap(); + for index in 0..(width * height) { + let y = index / width; + let x = index % width; + let red = x % 255; + let green = y % 255; + let blue = (x * y) % 255; + + buffer[index as usize] = blue | (green << 8) | (red << 16); + } + + buffer.present().unwrap(); } - - buffer.present().unwrap(); - } - Event::WindowEvent { - event: WindowEvent::CloseRequested, - window_id, - } if window_id == window.id() => { - elwt.exit(); + Event::WindowEvent { + event: WindowEvent::CloseRequested, + window_id, + } if window_id == window.id() => { + elwt.exit(); + } + _ => {} } - _ => {} - } -}); + }); -event_loop.run_app(&mut app).unwrap(); + event_loop.run_app(&mut app).unwrap(); +} ``` Changelog diff --git a/src/lib.rs b/src/lib.rs index 06cd6db..1bd445b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![doc = include_str!("../README.md")] +#![allow(clippy::needless_doctest_main)] #![deny(unsafe_op_in_unsafe_fn)] #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))]