card: split up into its own module.
This commit is contained in:
56
src/card/display.rs
Normal file
56
src/card/display.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use crate::card::{Card, PlayingCard, Rank, Suit};
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
impl Display for Rank {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
Rank::Jack => "J",
|
||||
Rank::Queen => "Q",
|
||||
Rank::King => "K",
|
||||
Rank::Ace => "A",
|
||||
Rank::Two => "2",
|
||||
Rank::Three => "3",
|
||||
Rank::Four => "4",
|
||||
Rank::Five => "5",
|
||||
Rank::Six => "6",
|
||||
Rank::Seven => "7",
|
||||
Rank::Eight => "8",
|
||||
Rank::Nine => "9",
|
||||
Rank::Ten => "10",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Suit {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
Suit::Diamond => "♦",
|
||||
Suit::Club => "♣",
|
||||
Suit::Heart => "♥",
|
||||
Suit::Spade => "♠",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PlayingCard {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}[{}]", self.rank, self.suit)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Card {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Card::Joker(_) => write!(f, "Joker"),
|
||||
Card::PlayingCard(card) => write!(f, "{}", card),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user