1use core::fmt;
4
5pub const BASE_CARD_ERROR_CODE: i32 = 1000;
7pub const BASE_BLACKJACK_ERROR_CODE: i32 = 2000;
9pub const BASE_SOLITAIRE_ERROR_CODE: i32 = 3000;
11pub const BASE_ROCK_PAPER_SCISSORS_ERROR_CODE: i32 = 4000;
13pub const BASE_COIN_TOSS_ERROR_CODE: i32 = 5000;
15pub const BASE_DECK_ERROR_CODE: i32 = 6000;
17pub const BASE_SLOT_MACHINE_ERROR_CODE: i32 = 7000;
19
20#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
22pub struct GenericError {
23 pub error_code: i32,
25 pub error_message: String,
27}
28
29impl fmt::Display for GenericError {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 write!(f, "Error ({}): {}", self.error_code, self.error_message)
32 }
33}
34
35pub trait ErrorCode: fmt::Debug {
38 fn error_code(&self) -> i32;
40}
41
42impl<E: ErrorCode> From<E> for GenericError {
43 fn from(err: E) -> Self {
44 Self {
45 error_code: err.error_code(),
46 error_message: format!("{:?}", err),
47 }
48 }
49}