1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Card {
pub suit: Suit,
pub value: Value,
}
impl fmt::Display for Card {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} of {:?}", self.value, self.suit)
}
}
impl Card {
pub fn is_face(self) -> bool {
self.value == Value::Ace
|| self.value == Value::Jack
|| self.value == Value::Queen
|| self.value == Value::King
}
pub fn suit(self) -> Suit {
self.suit
}
pub fn value(self) -> Value {
self.value
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Suit {
Hearts,
Clubs,
Spades,
Diamonds,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Value {
Ace,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
}