From d7a94c2d5724cb5bc7f517b0ff5f9f63137d9fa2 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 19 Feb 2025 13:43:39 -0500 Subject: [PATCH] Board::what_if use Result --- src/board.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/board.rs b/src/board.rs index 67d3ad0..675f1f0 100644 --- a/src/board.rs +++ b/src/board.rs @@ -234,14 +234,14 @@ impl Board { /// Return a modified [`Board`] with the piece placed at a position /// Returns None if the move was invalid - pub fn what_if(&self, i: usize, j: usize, piece: Piece) -> Option { + pub fn what_if(&self, i: usize, j: usize, piece: Piece) -> Result { // extract check here to avoid copy if self.get(i, j).is_some() { - return None; + return Err("position is occupied"); } let mut self_copy = *self; - self_copy.place(i, j, piece).ok().map(|_| self_copy) + self_copy.place(i, j, piece).map(|_| self_copy) } /// Returns a bool which represents whether or not a move would propegate and be valid