From ab851637239c46dfdfe73be316721d9fc4e7217a Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 5 Sep 2023 18:04:50 -0700 Subject: [PATCH] Fix clippy warnings --- septadrop/src/main.rs | 122 ++++++++++++++++----------------- septadrop/src/structs/block.rs | 2 +- 2 files changed, 60 insertions(+), 64 deletions(-) diff --git a/septadrop/src/main.rs b/septadrop/src/main.rs index a1c1b76..8f512b6 100644 --- a/septadrop/src/main.rs +++ b/septadrop/src/main.rs @@ -23,7 +23,7 @@ pub fn texture(name: &str) -> String { } fn get_level(lines: u32) -> u32 { - return std::cmp::min(lines / LINES_PER_LEVEL, 15); + std::cmp::min(lines / LINES_PER_LEVEL, 15) } fn get_update_interval(level: u32) -> u32 { @@ -53,7 +53,7 @@ fn handle_resize_events(code: Key, current_scale: &mut u32, render_window: &mut render_window.set_size(Vector2u::new(WINDOW_WIDTH, WINDOW_HEIGHT) * new_current_scale); let mut file = std::fs::OpenOptions::new() .write(true) - .open(&scale_file_path) + .open(scale_file_path) .unwrap(); file.write_all(new_current_scale.to_string().as_bytes()).unwrap(); file.flush().unwrap(); @@ -206,67 +206,64 @@ fn main() { let mut new_highscore_sound = Sound::with_buffer(&new_highscore_buffer); while window.is_open() { - loop { - match window.poll_event() { - Some(event) => match event { - Event::Closed | Event::KeyPressed { - code: Key::Q, - alt: _, - ctrl: true, - shift: _, - system: _, - } => window.close(), - Event::LostFocus => { - toggle_pause = true; - paused_from_lost_focus = true; + while let Some(event) = window.poll_event() { + match event { + Event::Closed | Event::KeyPressed { + code: Key::Q, + alt: _, + ctrl: true, + shift: _, + system: _, + } => window.close(), + Event::LostFocus => { + toggle_pause = true; + paused_from_lost_focus = true; + } + Event::KeyPressed { + code, + alt: _, + ctrl: true, + shift: _, + system: _, + } => { + handle_resize_events(code, &mut current_scale, &mut window, &scale_file_path); + }, + Event::KeyPressed { + code, + alt: _, + ctrl: _, + shift: _, + system: _, + } => match code { + Key::ESCAPE => toggle_pause = true, + Key::SPACE => snap = true, + Key::UP => rotate = true, + Key::DOWN => fast_forward = true, + Key::LEFT => { + move_left = true; + move_left_immediate = true; + move_clock.restart(); + } + Key::RIGHT => { + move_right = true; + move_right_immediate = true; + move_clock.restart(); } - Event::KeyPressed { - code, - alt: _, - ctrl: true, - shift: _, - system: _, - } => { - handle_resize_events(code, &mut current_scale, &mut window, &scale_file_path); - }, - Event::KeyPressed { - code, - alt: _, - ctrl: _, - shift: _, - system: _, - } => match code { - Key::ESCAPE => toggle_pause = true, - Key::SPACE => snap = true, - Key::UP => rotate = true, - Key::DOWN => fast_forward = true, - Key::LEFT => { - move_left = true; - move_left_immediate = true; - move_clock.restart(); - } - Key::RIGHT => { - move_right = true; - move_right_immediate = true; - move_clock.restart(); - } - _ => {} - }, - Event::KeyReleased { - code, - alt: _, - ctrl: _, - shift: _, - system: _, - } => match code { - Key::DOWN => fast_forward = false, - Key::LEFT => move_left = false, - Key::RIGHT => move_right = false, - _ => {} - }, _ => {} }, - None => break, + Event::KeyReleased { + code, + alt: _, + ctrl: _, + shift: _, + system: _, + } => match code { + Key::DOWN => fast_forward = false, + Key::LEFT => move_left = false, + Key::RIGHT => move_right = false, + _ => {} + }, + _ => {} } } @@ -297,8 +294,8 @@ fn main() { if paused { loop { - match window.wait_event() { - Some(event) => match event { + if let Some(event) = window.wait_event() { + match event { Event::Closed | Event::KeyPressed { code: Key::Q, alt: _, @@ -332,7 +329,6 @@ fn main() { }, _ => {} } - _ => {} } } } diff --git a/septadrop/src/structs/block.rs b/septadrop/src/structs/block.rs index f29e3f1..049e01b 100644 --- a/septadrop/src/structs/block.rs +++ b/septadrop/src/structs/block.rs @@ -29,7 +29,7 @@ impl<'a> Block<'a> { if !cell { continue; } - let mut rotated = Vector2i::new(x as i32, y as i32); + let mut rotated = Vector2i::new(x, y); if self.block_type.rotate { let center_x = row.len() as i32 / 2; let center_y = self.block_type.grid.len() as i32 / 2;