Pass self by reference to move builder methods where possible

This commit is contained in:
Eryn Wells 2024-02-25 08:57:16 -08:00
parent b5d4069751
commit d714374f35

View file

@ -246,7 +246,7 @@ impl Builder<Null> {
Self::push(piece).capturing_piece(&capturing) Self::push(piece).capturing_piece(&capturing)
} }
pub fn from(self, square: Square) -> Builder<Push> { pub fn from(&self, square: Square) -> Builder<Push> {
Builder { Builder {
style: Push { style: Push {
from: Some(square), from: Some(square),
@ -266,13 +266,13 @@ impl Builder<Push> {
self self
} }
pub fn to(mut self, square: Square) -> Self { pub fn to(&mut self, square: Square) -> &mut Self {
self.style.to = Some(square); self.style.to = Some(square);
self self
} }
pub fn capturing_on(self, square: Square) -> Builder<Capture> { pub fn capturing_on(&self, square: Square) -> Builder<Capture> {
let mut style = self.style; let mut style = self.style.clone();
style.to = Some(square); style.to = Some(square);
Builder { Builder {
@ -283,10 +283,10 @@ impl Builder<Push> {
} }
} }
pub fn capturing_en_passant_on(self, square: Square) -> Builder<EnPassantCapture> { pub fn capturing_en_passant_on(&self, square: Square) -> Builder<EnPassantCapture> {
match EnPassant::from_target_square(square) { match EnPassant::from_target_square(square) {
Some(en_passant) => { Some(en_passant) => {
let mut style = self.style; let mut style = self.style.clone();
style.to = Some(en_passant.target_square()); style.to = Some(en_passant.target_square());
Builder { Builder {
@ -300,19 +300,19 @@ impl Builder<Push> {
} }
} }
pub fn capturing_piece(self, piece: &PlacedPiece) -> Builder<Capture> { pub fn capturing_piece(&self, piece: &PlacedPiece) -> Builder<Capture> {
Builder { Builder {
style: Capture { style: Capture {
push: self.style, push: self.style.clone(),
capture: Some(piece.square()), capture: Some(piece.square()),
}, },
} }
} }
pub fn promoting_to(self, shape: PromotionShape) -> Builder<Promotion<Push>> { pub fn promoting_to(&self, shape: PromotionShape) -> Builder<Promotion<Push>> {
Builder { Builder {
style: Promotion { style: Promotion {
style: self.style, style: self.style.clone(),
promotion: shape, promotion: shape,
}, },
} }