Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
**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]: rust-lang/rust#71269
[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1348ce2173e812ff4199446a4fed5a99
  • Loading branch information
Mark Lodato committed May 6, 2022
1 parent 37274a1 commit 12775ea
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -168,13 +168,10 @@ fn keyboard_input(keys: Res<Input<KeyCode>>, 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:
// <https://doc.rust-lang.org/reference/expressions/operator-expr.html#numeric-cast>.
sample as i16
}

/// This async function must be executed in an async runtime, and it will return a websocket handle
Expand Down

0 comments on commit 12775ea

Please sign in to comment.