From 12775eac74dac759ac873c5520de386d89cf0bb9 Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Fri, 6 May 2022 13:10:29 -0400 Subject: [PATCH] Fix `clippy` lints **This Commit** Just fixes two small `clippy` lints. **Note** When handling one of the `clippy` lints (unnecessary `return`) I took a look at `f32_to_i16` and it looked to me like this was doing a saturating cast. If that's the case then, after [doing some research][0], it looks like `as` [already does saturating casts][1]! [0]: https://github.com/rust-lang/rust/pull/71269 [1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1348ce2173e812ff4199446a4fed5a99 --- src/main.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index dbebbad..d33b6e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,7 @@ fn spawn_enemy(mut commands: Commands) { commands .spawn_bundle(SpriteBundle { sprite: Sprite { - color: Color::rgb(0.75, 0.75, 0.75).into(), + color: Color::rgb(0.75, 0.75, 0.75), custom_size: Some(Vec2::new( ENEMY_HALF_EXTENDS * 2.0, ENEMY_HALF_EXTENDS * 2.0, @@ -168,13 +168,10 @@ fn keyboard_input(keys: Res>, mut query: Query<&mut Velocity, Wit /// Deepgram currently does not support f32 PCM. fn f32_to_i16(sample: f32) -> i16 { let sample = sample * 32768.0; - if sample > 32767.0 { - return 32767; - } - if sample < -32768.0 { - return -32768; - } - return sample as i16; + + // This is a saturating cast. For more details, see: + // . + sample as i16 } /// This async function must be executed in an async runtime, and it will return a websocket handle