games/blackjack/
errors.rs1use crate::errors::BASE_BLACKJACK_ERROR_CODE;
2use core::fmt;
3
4#[repr(C)]
6#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
7pub enum BlackJackError {
8 PlayerLostError,
10 PlayerWonError,
12 OutOfCardsError,
14}
15
16impl fmt::Display for BlackJackError {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 use BlackJackError::*;
19 match *self {
20 PlayerLostError => {
21 f.write_str("Player has lost the game, no other actions can be made.")
22 }
23 PlayerWonError => f.write_str("Player has won the game, no other actions can be made."),
24 OutOfCardsError => f.write_str("The game has run out of cards in the deck."),
25 }
26 }
27}
28
29impl crate::errors::ErrorCode for BlackJackError {
30 fn error_code(&self) -> i32 {
31 BASE_BLACKJACK_ERROR_CODE
32 + match *self {
33 BlackJackError::PlayerLostError => 1,
34 BlackJackError::PlayerWonError => 2,
35 BlackJackError::OutOfCardsError => 3,
36 }
37 }
38}