server/domain/scoring/
score_item.rs1use serde::{Deserialize, Serialize};
2
3use crate::{
4 display::format_vec,
5 domain::{Card, Points, ScoreKind},
6};
7
8#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
15pub struct ScoreItem {
16 kind: ScoreKind,
17 cards: Vec<Card>,
18 points: Points,
19}
20
21impl ScoreItem {
22 pub fn new(kind: ScoreKind, cards: Vec<Card>, points: Points) -> Self {
25 Self {
26 kind,
27 cards,
28 points,
29 }
30 }
31
32 #[must_use]
34 pub fn kind(&self) -> ScoreKind {
35 self.kind
36 }
37
38 #[must_use]
40 pub fn cards(&self) -> &Vec<Card> {
41 &self.cards
42 }
43
44 #[must_use]
46 pub fn points(&self) -> Points {
47 self.points
48 }
49}
50
51impl std::fmt::Display for ScoreItem {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 write!(
54 f,
55 "{}: ({}) -> {}",
56 self.kind.as_ref(),
57 format_vec(self.cards.as_slice()),
58 self.points
59 )
60 }
61}