From c73ab25c9dbe40284cfd38beaf31e2a20a9810de Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 22 Sep 2026 18:22:46 +0200 Subject: refactor(engine): fix portion of clippy lints --- engine/src/windowing/keyboard.rs | 48 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'engine/src/windowing/keyboard.rs') diff --git a/engine/src/windowing/keyboard.rs b/engine/src/windowing/keyboard.rs index dffa95e..a8ec6df 100644 --- a/engine/src/windowing/keyboard.rs +++ b/engine/src/windowing/keyboard.rs @@ -14,6 +14,7 @@ impl Keyboard { /// Returns whether the given key was just pressed this frame. This function will /// return `false` if the key was also pressed the previous frame. + #[must_use] pub fn just_pressed(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Pressed @@ -22,6 +23,7 @@ impl Keyboard /// Returns whether the given key was just released this frame. This function will /// return `false` if the key was also released the previous frame. + #[must_use] pub fn just_released(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Released @@ -29,12 +31,14 @@ impl Keyboard } /// Returns whether the given key is currently pressed. + #[must_use] pub fn pressed(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Pressed } /// Returns whether the given key is currently released. + #[must_use] pub fn released(&self, key: Key) -> bool { self.get_key_state(key) == KeyState::Released @@ -66,13 +70,11 @@ impl Keyboard { let bits = self.keys.get(key as usize); - let state = match bits & KEY_CURR_PRESSED_BITS { + match bits & KEY_CURR_PRESSED_BITS { KEY_CURR_PRESSED_BITS => KeyState::Pressed, 0 => KeyState::Released, _ => unreachable!(), - }; - - state + } } #[must_use] @@ -80,15 +82,14 @@ impl Keyboard { let bits = self.keys.get(key as usize); - let state = match bits & KEY_PREV_PRESSED_BITS { + match bits & KEY_PREV_PRESSED_BITS { KEY_PREV_PRESSED_BITS => KeyState::Pressed, 0 => KeyState::Released, _ => unreachable!(), - }; - - state + } } + #[must_use] pub fn text_keys(&self) -> &str { &self.text_keys @@ -109,7 +110,7 @@ impl Keyboard pub fn make_key_states_previous(&mut self) { for byte in self.keys.bytes_mut() { - *byte = (*byte >> 1) & 0b01010101 | *byte & 0b10101010; + *byte = (*byte >> 1) & 0b0101_0101 | *byte & 0b1010_1010; } } @@ -125,7 +126,7 @@ impl Keyboard #[non_exhaustive] pub enum Key { - /// ` on a US keyboard. This is also called a backtick or grave. + #[doc = "` on a US keyboard. This is also called a backtick or grave."] /// This is the 半角/全角/漢字 /// (hankaku/zenkaku/kanji) key on Japanese keyboards Backquote, @@ -243,12 +244,12 @@ pub enum Key /// Alt, Option, or . AltLeft, /// Alt, Option, or . - /// This is labeled AltGr on many keyboard layouts. + /// This is labeled `AltGr` on many keyboard layouts. AltRight, /// Backspace or . /// Labeled Delete on Apple keyboards. Backspace, - /// CapsLock or + /// `CapsLock` or CapsLock, /// The application context menu key, which is typically found between the right /// Super key and the right Control key. @@ -276,7 +277,7 @@ pub enum Key /// Japanese: カタカナ/ひらがな/ローマ字 /// (katakana/hiragana/romaji) KanaMode, - /// Korean: HangulMode 한/영 (han/yeong) + /// Korean: `HangulMode` 한/영 (han/yeong) /// /// Japanese (Mac keyboard): (kana) Lang1, @@ -306,9 +307,9 @@ pub enum Key Home, /// Insert or Ins. Not present on Apple keyboards. Insert, - /// Page Down, PgDn, or + /// Page Down, `PgDn`, or PageDown, - /// Page Up, PgUp, or + /// Page Up, `PgUp`, or PageUp, /// ArrowDown, @@ -327,7 +328,7 @@ pub enum Key Numpad1, /// 2 ↓ on a keyboard. 2 ABC on a phone or remote control Numpad2, - /// 3 PgDn on a keyboard. 3 DEF on a phone or remote control + /// 3 `PgDn` on a keyboard. 3 DEF on a phone or remote control Numpad3, /// 4 ← on a keyboard. 4 GHI on a phone or remote control Numpad4, @@ -340,15 +341,15 @@ pub enum Key Numpad7, /// 8 ↑ on a keyboard. 8 TUV on a phone or remote control Numpad8, - /// 9 PgUp on a keyboard. 9 WXYZ or 9 WXY on a phone - /// or remote control + /// 9 `PgUp` on a keyboard. 9 WXYZ or 9 WXY on a + /// phone or remote control Numpad9, /// + NumpadAdd, /// Found on the Microsoft Natural Keyboard. NumpadBackspace, /// C or A (All Clear). Also for use with numpads that have a - /// Clear key that is separate from the NumLock key. On the + /// Clear key that is separate from the `NumLock` key. On the /// Mac, the numpad Clear key is encoded as [`NumLock`]. /// /// [`NumLock`]: Self::NumLock @@ -393,7 +394,7 @@ pub enum Key /// This key is typically found below the 7 key and to the left of /// the 0 key. /// - /// Use "NumpadMultiply" for the * key on + /// Use "`NumpadMultiply`" for the * key on /// numeric keypads. NumpadStar, /// - @@ -403,10 +404,10 @@ pub enum Key /// Fn This is typically a hardware key that does not generate a separate /// code. Fn, - /// FLock or FnLock. Function Lock key. Found on the Microsoft - /// Natural Keyboard. + /// `FLock` or `FnLock`. Function Lock key. Found on the + /// Microsoft Natural Keyboard. FnLock, - /// PrtScr SysRq or Print Screen + /// `PrtScr` `SysRq` or Print Screen PrintScreen, /// Scroll Lock ScrollLock, @@ -577,6 +578,7 @@ impl TryFrom for Key { type Error = UnknownKeyCodeError; + #[allow(clippy::too_many_lines)] fn try_from(key_code: winit::keyboard::KeyCode) -> Result { match key_code { -- cgit v1.2.3-18-g5258