server/domain/cards/cuts_for_deal.rs
1pub use crate::domain::{Card, Player};
2
3/// The two cards cut by the players to determine who deals first.
4///
5/// Indices are host and guest respectively.
6/// `None` means that player has not yet cut.
7///
8/// In Cribbage, the lower card wins the deal. Ties cause a redraw.
9pub type CutsForDeal = [Option<Card>; 2];
10
11/// Trait for game states that track the "cut for deal" phase.
12pub trait HasCutsForDeal {
13 /// Immutable access to both cuts.
14 fn cuts_for_deal(&self) -> &CutsForDeal;
15
16 /// Mutable access to both cuts.
17 fn cuts_for_deal_mut(&mut self) -> &mut CutsForDeal;
18
19 /// Returns the card cut by the given player, if any.
20 #[must_use]
21 fn cut_for_deal(&self, player: Player) -> Option<&Card> {
22 self.cuts_for_deal()[player].as_ref()
23 }
24
25 /// Returns a mutable reference to the cut slot for the given player.
26 #[must_use]
27 fn cut_for_deal_mut(&mut self, player: Player) -> &mut Option<Card> {
28 &mut self.cuts_for_deal_mut()[player]
29 }
30}