server/domain/players/
dealer.rs1use serde::{Deserialize, Serialize};
2
3use super::{Player, Pone};
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
10#[repr(transparent)]
11#[serde(transparent)]
12pub struct Dealer(Player);
13
14impl Dealer {
15 pub const fn player(&self) -> Player {
17 self.0
18 }
19
20 pub fn opponent(&self) -> Pone {
22 Pone::from(self.0.opponent())
23 }
24}
25
26impl<T> std::ops::Index<Dealer> for [T] {
27 type Output = T;
28
29 fn index(&self, index: Dealer) -> &Self::Output {
30 &self[index.0]
31 }
32}
33
34impl<T> std::ops::Index<&Dealer> for [T] {
35 type Output = T;
36
37 fn index(&self, index: &Dealer) -> &Self::Output {
38 &self[index.0]
39 }
40}
41
42impl From<Player> for Dealer {
43 fn from(value: Player) -> Self {
44 Self(value)
45 }
46}
47
48impl std::fmt::Display for Dealer {
49 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50 write!(f, "Dealer({})", self.0)
51 }
52}