Skip to main content

server/domain/players/
pone.rs

1use serde::{Deserialize, Serialize};
2
3use super::{Dealer, Player};
4
5/// Represents the pone (non-dealer) player in a two-player game.
6///
7/// This type wraps a `Player` and provides convenient access to the
8/// corresponding pone in the round.
9#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
10#[repr(transparent)]
11#[serde(transparent)]
12pub struct Pone(Player);
13
14impl Pone {
15    /// Returns the underlying `Player` representing the pone.
16    #[must_use]
17    pub const fn player(&self) -> Player {
18        self.0
19    }
20
21    /// Returns the opponent (dealer) of this pone.
22    #[must_use]
23    pub fn opponent(&self) -> Dealer {
24        Dealer::from(self.0.opponent())
25    }
26}
27
28impl<T> std::ops::Index<Pone> for [T] {
29    type Output = T;
30
31    fn index(&self, index: Pone) -> &Self::Output {
32        &self[index.0]
33    }
34}
35
36impl<T> std::ops::Index<&Pone> for [T] {
37    type Output = T;
38
39    fn index(&self, index: &Pone) -> &Self::Output {
40        &self[index.0]
41    }
42}
43
44impl From<Player> for Pone {
45    fn from(value: Player) -> Self {
46        Self(value)
47    }
48}
49
50impl std::fmt::Display for Pone {
51    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52        write!(f, "Pone({})", self.0)
53    }
54}