cribbage_core/pegging/
one_card_pegging.rs

1use crate::card::Card;
2use crate::pegging::Pegger;
3use crate::CribbageCoreError;
4
5#[derive(Clone, Copy)]
6pub struct OneCardPegging {
7    card: Card,
8}
9
10impl OneCardPegging {
11    pub(in crate::pegging) fn new(card: Card) -> OneCardPegging {
12        OneCardPegging { card }
13    }
14
15    pub fn play_card(
16        self,
17        card: Card,
18        pegger: &mut Pegger,
19    ) -> Result<u8, (Self, CribbageCoreError)> {
20        if card != self.card {
21            return Err((self, CribbageCoreError::InvalidCard));
22        }
23
24        match pegger.play_card(card) {
25            Ok(points) => Ok(points),
26            Err(error) => Err((self, error)),
27        }
28    }
29}