cargo clippy --fix

This commit is contained in:
Max Känner 2024-10-05 20:19:49 +02:00
parent 16c78c81ae
commit bb356427df
3 changed files with 11 additions and 11 deletions

View File

@ -30,7 +30,7 @@ use crate::{
// info is called when you create your Battlesnake on play.battlesnake.com // info is called when you create your Battlesnake on play.battlesnake.com
// and controls your Battlesnake's appearance // and controls your Battlesnake's appearance
// TIP: If you open your Battlesnake URL in a browser you should see this data // TIP: If you open your Battlesnake URL in a browser you should see this data
pub fn info() -> Value { #[must_use] pub fn info() -> Value {
info!("INFO"); info!("INFO");
json!({ json!({

View File

@ -7,7 +7,7 @@ use rocket::{
get, get,
http::Status, http::Status,
launch, post, routes, launch, post, routes,
serde::{json::Json, Deserialize}, serde::json::Json,
tokio::task, tokio::task,
}; };
use serde_json::Value; use serde_json::Value;

View File

@ -14,7 +14,7 @@ pub struct SnakeToken {
} }
impl SnakeToken { impl SnakeToken {
pub fn from_board(board: &crate::Board) -> BTreeMap<String, Self> { #[must_use] pub fn from_board(board: &crate::Board) -> BTreeMap<String, Self> {
board board
.snakes .snakes
.iter() .iter()
@ -52,7 +52,7 @@ pub struct Board {
} }
impl Board { impl Board {
pub fn from_game_board( #[must_use] pub fn from_game_board(
board: &crate::Board, board: &crate::Board,
token_map: &BTreeMap<String, SnakeToken>, token_map: &BTreeMap<String, SnakeToken>,
turn: i32, turn: i32,
@ -86,16 +86,16 @@ impl Board {
} }
} }
pub const fn turn(&self) -> i32 { #[must_use] pub const fn turn(&self) -> i32 {
self.turn self.turn
} }
#[allow(clippy::cast_sign_loss)] #[allow(clippy::cast_sign_loss)]
pub const fn spaces(&self) -> usize { #[must_use] pub const fn spaces(&self) -> usize {
self.height as usize * self.width as usize self.height as usize * self.width as usize
} }
pub fn alive_snakes(&self) -> usize { #[must_use] pub fn alive_snakes(&self) -> usize {
self.snakes.len() self.snakes.len()
} }
@ -103,7 +103,7 @@ impl Board {
self.snakes.keys().copied() self.snakes.keys().copied()
} }
pub fn snake_length(&self, token: SnakeToken) -> Option<usize> { #[must_use] pub fn snake_length(&self, token: SnakeToken) -> Option<usize> {
self.snakes.get(&token).map(|snake| snake.body.len()) self.snakes.get(&token).map(|snake| snake.body.len())
} }
@ -196,7 +196,7 @@ impl Board {
} }
} }
pub fn possible_actions(&self) -> BTreeMap<SnakeToken, BTreeSet<Direction>> { #[must_use] pub fn possible_actions(&self) -> BTreeMap<SnakeToken, BTreeSet<Direction>> {
let mut actions: BTreeMap<_, BTreeSet<_>> = self let mut actions: BTreeMap<_, BTreeSet<_>> = self
.snakes .snakes
.keys() .keys()
@ -272,7 +272,7 @@ pub struct Battlesnake {
} }
impl Battlesnake { impl Battlesnake {
pub fn from_game_snake(snake: &crate::Battlesnake) -> Self { #[must_use] pub fn from_game_snake(snake: &crate::Battlesnake) -> Self {
let body: VecDeque<_> = snake.body.iter().copied().collect(); let body: VecDeque<_> = snake.body.iter().copied().collect();
debug_assert_eq!(body.len(), usize::try_from(snake.length).unwrap()); debug_assert_eq!(body.len(), usize::try_from(snake.length).unwrap());
debug_assert!(snake.health <= crate::MAX_HEALTH); debug_assert!(snake.health <= crate::MAX_HEALTH);
@ -295,7 +295,7 @@ impl Battlesnake {
self.health = self.health.saturating_sub(1); self.health = self.health.saturating_sub(1);
} }
pub fn head(&self) -> &Coord { #[must_use] pub fn head(&self) -> &Coord {
debug_assert!(!self.body.is_empty()); debug_assert!(!self.body.is_empty());
self.body.front().expect("not empty") self.body.front().expect("not empty")
} }