From 086135abb58e5e2b7aa769eafb6158fb45b249e9 Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Mon, 24 Feb 2025 22:34:52 +0000 Subject: [PATCH] Errors are passed through "properly" --- card_stuffs/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/card_stuffs/src/lib.rs b/card_stuffs/src/lib.rs index db31461..a20896f 100644 --- a/card_stuffs/src/lib.rs +++ b/card_stuffs/src/lib.rs @@ -114,22 +114,22 @@ pub enum StackingError { #[error("Trying to stack the same coloured suit")] SameColour, #[error("{0} is not \"next\" to {1}")] - NotAdjacent(Card, Card), + NotAdjacent(String, String), } impl Card { - pub fn can_be_placed_on_top(&self, top: Card) -> bool { + pub fn can_be_placed_on_top(&self, top: Card) -> Result<(), StackingError> { // Can't be the same Colour if self.suit.colour() != top.suit.colour() { - return false + return Err(StackingError::SameColour); } // Needs to be adjascent if self.value == Value::King || self.value.indexed_values() != top.value.indexed_values() + 1 { - return false + return Err(StackingError::NotAdjacent(self.to_string(), top.to_string())); } - true + Ok(()) } }