Skip to main content

server/domain/plays/
play.rs

1use serde::{Deserialize, Serialize};
2
3use crate::domain::{Card, Player};
4
5/// Represents a single play in the pegging phase of the game.
6///
7/// A `Play` pairs a player with the card they played.
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
9pub struct Play {
10    player: Player,
11    card: Card,
12}
13
14impl Play {
15    /// Creates a new `Play` with the given player and card.
16    #[must_use]
17    pub fn new<P: Into<Player>>(player: P, card: Card) -> Self {
18        let player = player.into();
19        Self { player, card }
20    }
21
22    /// Returns the player who made this play.
23    #[must_use]
24    pub const fn player(&self) -> Player {
25        self.player
26    }
27
28    /// Returns the card played.
29    #[must_use]
30    pub const fn card(&self) -> Card {
31        self.card
32    }
33}
34
35impl std::fmt::Display for Play {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        write!(f, "({} -> {})", self.player, self.card)
38    }
39}