Errors are passed through "properly"

This commit is contained in:
2025-02-24 22:34:52 +00:00
parent ff801f259d
commit 086135abb5

View File

@@ -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(())
}
}