Fix misc clippy suggestions

This commit is contained in:
2021-12-11 17:28:06 +01:00
parent 7dabb49cd4
commit 7143427dd2

View File

@@ -47,10 +47,7 @@ impl Position {
self.file.delta(delta_file)?, self.file.delta(delta_file)?,
)) ))
} }
fn deltas_to_valid_positions( fn deltas_to_valid_positions(&self, deltas: &[(i8, i8)]) -> Vec<Position> {
&self,
deltas: &Vec<(i8, i8)>,
) -> Vec<Position> {
deltas deltas
.iter() .iter()
.filter_map(|&delta_rank_file| self.delta(delta_rank_file).ok()) .filter_map(|&delta_rank_file| self.delta(delta_rank_file).ok())
@@ -89,9 +86,7 @@ where
{ {
const ALL_VALUES: [Self; 8]; const ALL_VALUES: [Self; 8];
fn new(index: u8) -> Result<Self, ()> { fn new(index: u8) -> Result<Self, ()> {
return Ok( Ok(Self::ALL_VALUES[Self::validate_index(index)? as usize].clone())
Self::ALL_VALUES[Self::validate_index(index)? as usize].clone()
);
} }
fn validate_index(index: u8) -> Result<u8, ()> { fn validate_index(index: u8) -> Result<u8, ()> {
if index as usize >= Self::ALL_VALUES.len() { if index as usize >= Self::ALL_VALUES.len() {
@@ -194,14 +189,14 @@ impl Piece {
fn _pawn_get_move_deltas(&self, position: &Position) -> Vec<(i8, i8)> { fn _pawn_get_move_deltas(&self, position: &Position) -> Vec<(i8, i8)> {
let direction = self.color.get_direction(); let direction = self.color.get_direction();
if position.rank == self.color.get_pawn_rank() { if position.rank == self.color.get_pawn_rank() {
vec![(1 * direction, 0), (2 * direction, 0)] vec![(direction, 0), (2 * direction, 0)]
} else { } else {
vec![(1 * direction, 0)] vec![(direction, 0)]
} }
} }
fn _pawn_get_capture_deltas(&self) -> Vec<(i8, i8)> { fn _pawn_get_capture_deltas(&self) -> Vec<(i8, i8)> {
let direction = self.color.get_direction(); let direction = self.color.get_direction();
vec![(1 * direction, 1), (1 * direction, -1)] vec![(direction, 1), (direction, -1)]
} }
} }
@@ -211,7 +206,7 @@ pub struct Board {
impl Board { impl Board {
pub fn get_at(&self, position: &Position) -> Option<&Piece> { pub fn get_at(&self, position: &Position) -> Option<&Piece> {
return self.state.get(position); self.state.get(position)
} }
pub fn set_at( pub fn set_at(
&mut self, &mut self,