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)
}
pub fn from(self, square: Square) -> Builder<Push> {
pub fn from(&self, square: Square) -> Builder<Push> {
Builder {
style: Push {
from: Some(square),
@ -266,13 +266,13 @@ impl Builder<Push> {
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<Capture> {
let mut style = self.style;
pub fn capturing_on(&self, square: Square) -> Builder<Capture> {
let mut style = self.style.clone();
style.to = Some(square);
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) {
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<Push> {
}
}
pub fn capturing_piece(self, piece: &PlacedPiece) -> Builder<Capture> {
pub fn capturing_piece(&self, piece: &PlacedPiece) -> Builder<Capture> {
Builder {
style: Capture {
push: self.style,
push: self.style.clone(),
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 {
style: Promotion {
style: self.style,
style: self.style.clone(),
promotion: shape,
},
}