Skip to content

Commit 12775ea

Browse files
author
Mark Lodato
committed
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]: rust-lang/rust#71269 [1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1348ce2173e812ff4199446a4fed5a99
1 parent 37274a1 commit 12775ea

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/main.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn spawn_enemy(mut commands: Commands) {
8989
commands
9090
.spawn_bundle(SpriteBundle {
9191
sprite: Sprite {
92-
color: Color::rgb(0.75, 0.75, 0.75).into(),
92+
color: Color::rgb(0.75, 0.75, 0.75),
9393
custom_size: Some(Vec2::new(
9494
ENEMY_HALF_EXTENDS * 2.0,
9595
ENEMY_HALF_EXTENDS * 2.0,
@@ -168,13 +168,10 @@ fn keyboard_input(keys: Res<Input<KeyCode>>, mut query: Query<&mut Velocity, Wit
168168
/// Deepgram currently does not support f32 PCM.
169169
fn f32_to_i16(sample: f32) -> i16 {
170170
let sample = sample * 32768.0;
171-
if sample > 32767.0 {
172-
return 32767;
173-
}
174-
if sample < -32768.0 {
175-
return -32768;
176-
}
177-
return sample as i16;
171+
172+
// This is a saturating cast. For more details, see:
173+
// <https://doc.rust-lang.org/reference/expressions/operator-expr.html#numeric-cast>.
174+
sample as i16
178175
}
179176

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

0 commit comments

Comments
 (0)