card:default: implemented defaults for every card type
This commit is contained in:
25
src/card/default.rs
Normal file
25
src/card/default.rs
Normal 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())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
mod default;
|
||||||
mod display;
|
mod display;
|
||||||
mod hash;
|
mod hash;
|
||||||
mod impls;
|
mod impls;
|
||||||
@@ -41,10 +42,3 @@ pub enum Card {
|
|||||||
Joker(i64),
|
Joker(i64),
|
||||||
PlayingCard(PlayingCard),
|
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)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user