From d714374f35ee63a9a8976f547fe7fadc2cae835a Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 25 Feb 2024 08:57:16 -0800 Subject: [PATCH] Pass self by reference to move builder methods where possible --- moves/src/builder.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/moves/src/builder.rs b/moves/src/builder.rs index b71c432..a1ab78e 100644 --- a/moves/src/builder.rs +++ b/moves/src/builder.rs @@ -246,7 +246,7 @@ impl Builder { Self::push(piece).capturing_piece(&capturing) } - pub fn from(self, square: Square) -> Builder { + pub fn from(&self, square: Square) -> Builder { Builder { style: Push { from: Some(square), @@ -266,13 +266,13 @@ impl Builder { self } - pub fn to(mut self, square: Square) -> Self { + pub fn to(&mut self, square: Square) -> &mut Self { self.style.to = Some(square); self } - pub fn capturing_on(self, square: Square) -> Builder { - let mut style = self.style; + pub fn capturing_on(&self, square: Square) -> Builder { + let mut style = self.style.clone(); style.to = Some(square); Builder { @@ -283,10 +283,10 @@ impl Builder { } } - pub fn capturing_en_passant_on(self, square: Square) -> Builder { + pub fn capturing_en_passant_on(&self, square: Square) -> Builder { match EnPassant::from_target_square(square) { Some(en_passant) => { - let mut style = self.style; + let mut style = self.style.clone(); style.to = Some(en_passant.target_square()); Builder { @@ -300,19 +300,19 @@ impl Builder { } } - pub fn capturing_piece(self, piece: &PlacedPiece) -> Builder { + pub fn capturing_piece(&self, piece: &PlacedPiece) -> Builder { Builder { style: Capture { - push: self.style, + push: self.style.clone(), capture: Some(piece.square()), }, } } - pub fn promoting_to(self, shape: PromotionShape) -> Builder> { + pub fn promoting_to(&self, shape: PromotionShape) -> Builder> { Builder { style: Promotion { - style: self.style, + style: self.style.clone(), promotion: shape, }, }