server/domain/cards/hands.rs
1use constants::*;
2
3use crate::domain::{Hand, Player};
4
5/// Fixed-size array holding all players' hands.
6///
7/// Indexed by host & guest.
8pub type Hands = [Hand; PLAYER_COUNT];
9
10/// Trait for game states that have player hands.
11pub trait HasHands {
12 /// Immutable access to all hands.
13 fn hands(&self) -> &Hands;
14
15 /// Mutable access to all hands.
16 fn hands_mut(&mut self) -> &mut Hands;
17
18 /// Returns an immutable reference to the given player's hand.
19 #[must_use]
20 #[inline(always)]
21 fn hand(&self, player: Player) -> &Hand {
22 &self.hands()[player]
23 }
24
25 /// Returns a mutable reference to the given player's hand.
26 #[must_use]
27 #[inline(always)]
28 fn hand_mut(&mut self, player: Player) -> &mut Hand {
29 &mut self.hands_mut()[player]
30 }
31}