Fix some clippy warnings
This commit is contained in:
@@ -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()
|
||||
|
||||
16
src/grid.rs
16
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<Coordinate> 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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -87,13 +87,13 @@ impl SnakeSegments {
|
||||
impl Direction {
|
||||
fn from_keypress(keypress: Res<Input<KeyCode>>) -> Option<Self> {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user