card:default: implemented defaults for every card type

This commit is contained in:
2026-04-07 01:55:14 +01:00
committed by oreodave
parent 967374d688
commit b4cd7e8ea9
2 changed files with 26 additions and 7 deletions

25
src/card/default.rs Normal file
View File

@@ -0,0 +1,25 @@
use crate::card::{Card, PlayingCard, Rank, Suit};
impl Default for Rank {
fn default() -> Self {
Self::Three
}
}
impl Default for Suit {
fn default() -> Self {
Self::Diamond
}
}
impl Default for PlayingCard {
fn default() -> Self {
Self::new(0, Rank::default(), Suit::default())
}
}
impl Default for Card {
fn default() -> Self {
Self::PlayingCard(PlayingCard::default())
}
}

View File

@@ -1,3 +1,4 @@
mod default;
mod display;
mod hash;
mod impls;
@@ -41,10 +42,3 @@ pub enum Card {
Joker(i64),
PlayingCard(PlayingCard),
}
/** Given a sequence of Playing Cards, check if they are all of the same rank.
*/
pub fn all_same_rank(cards: &[PlayingCard]) -> bool {
let rank = cards[0].rank;
cards[1..].iter().all(|card| rank == card.rank)
}