card:impls: Card::{is_joker,playing_card,rank,suit}

This commit is contained in:
2026-04-09 19:18:00 +01:00
parent 8293033c3f
commit 283e02d782

View File

@@ -64,6 +64,25 @@ impl Card {
Self::PlayingCard(PlayingCard::new(deck, rank, suit)) Self::PlayingCard(PlayingCard::new(deck, rank, suit))
} }
pub fn is_joker(&self) -> bool {
matches!(self, Card::Joker(_))
}
fn playing_card(&self) -> Option<PlayingCard> {
match self {
Card::Joker(_) => None,
Card::PlayingCard(pc) => Some(*pc),
}
}
pub fn rank(&self) -> Option<Rank> {
self.playing_card().and_then(|pc| Some(pc.rank))
}
pub fn suit(&self) -> Option<Suit> {
self.playing_card().and_then(|pc| Some(pc.suit))
}
pub fn deck_abs(&self) -> i64 { pub fn deck_abs(&self) -> i64 {
match *self { match *self {
Self::Joker(x) => x, Self::Joker(x) => x,