From 0c59cfd898dfc10f80aa7f1978c039da793cdc1c Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Sun, 21 Aug 2022 13:46:08 +0200 Subject: [PATCH] Fix some clippy warnings --- src/canvas.rs | 2 +- src/grid.rs | 16 ++++++++-------- src/main.rs | 2 +- src/snake.rs | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/canvas.rs b/src/canvas.rs index 3eb314c..2fa7912 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -14,7 +14,7 @@ fn spawn_background(mut commands: Commands) { .spawn_bundle(SpriteBundle { sprite: Sprite { color: Color::DARK_GRAY, - custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE * grid::SIZE as f32)), + custom_size: Some(Vec2::splat(grid::SEGMENT_SIZE * f32::from(grid::SIZE))), ..Default::default() }, ..Default::default() diff --git a/src/grid.rs b/src/grid.rs index 111bfad..14eb4da 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -10,11 +10,11 @@ pub const SEGMENT_SIZE: f32 = 20.; pub struct Coordinate(pub Index, pub Index); impl Coordinate { - pub fn splat(v: Index) -> Self { + pub const fn splat(v: Index) -> Self { Self(v, v) } - pub fn in_bounds(self) -> bool { + pub const fn in_bounds(self) -> bool { self.0 >= 0 && self.0 < SIZE && self.1 >= 0 && self.1 < SIZE } } @@ -22,14 +22,14 @@ impl Coordinate { impl Add for Coordinate { type Output = Self; - fn add(self, rhs: Coordinate) -> Self::Output { - Coordinate(self.0 + rhs.0, self.1 + rhs.1) + fn add(self, rhs: Self) -> Self::Output { + Self(self.0 + rhs.0, self.1 + rhs.1) } } impl AddAssign for Coordinate { fn add_assign(&mut self, rhs: Self) { - *self = Self(self.0 + rhs.0, self.1 + rhs.1) + *self = Self(self.0 + rhs.0, self.1 + rhs.1); } } @@ -41,9 +41,9 @@ impl From for Vec2 { impl From<&Coordinate> for Vec2 { fn from(grid_coordinate: &Coordinate) -> Self { - Vec2::new( - (grid_coordinate.0 - SIZE / 2) as f32 * SEGMENT_SIZE, - (grid_coordinate.1 - SIZE / 2) as f32 * SEGMENT_SIZE, + Self::new( + f32::from(grid_coordinate.0 - SIZE / 2)* SEGMENT_SIZE, + f32::from(grid_coordinate.1 - SIZE / 2) * SEGMENT_SIZE, ) } } diff --git a/src/main.rs b/src/main.rs index 8e1fd0d..76f727d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ fn main() { } fn setup_system(mut commands: Commands) { - let grid_dimensions = SIZE as f32 * SEGMENT_SIZE * 1.2; + let grid_dimensions = f32::from(SIZE) * SEGMENT_SIZE * 1.2; commands .spawn_bundle(Camera2dBundle { diff --git a/src/snake.rs b/src/snake.rs index f0c01b9..99bf8f6 100644 --- a/src/snake.rs +++ b/src/snake.rs @@ -87,13 +87,13 @@ impl SnakeSegments { impl Direction { fn from_keypress(keypress: Res>) -> Option { if keypress.pressed(KeyCode::Up) { - Some(Direction::Up) + Some(Self::Up) } else if keypress.pressed(KeyCode::Down) { - Some(Direction::Down) + Some(Self::Down) } else if keypress.pressed(KeyCode::Left) { - Some(Direction::Left) + Some(Self::Left) } else if keypress.pressed(KeyCode::Right) { - Some(Direction::Right) + Some(Self::Right) } else { None }