card: add rank and suit destructors

They're Option since card may be a joker, but this is supremely
helpful.
This commit is contained in:
2026-03-31 23:19:14 +01:00
committed by oreodave
parent dfc5761246
commit b66c1c7706

View File

@@ -37,6 +37,20 @@ impl Card {
pub fn is_joker(&self) -> bool {
matches!(self, Self::Joker(_))
}
pub fn rank(&self) -> Option<Rank> {
match self {
Self::Joker(_) => None,
Self::PlayingCard { rank: rank, .. } => Some(*rank),
}
}
pub fn suit(&self) -> Option<Suit> {
match self {
Self::Joker(_) => None,
Self::PlayingCard { suit: suit, .. } => Some(*suit),
}
}
}
pub fn make_decks(number_of_decks: usize) -> Vec<Card> {