use core::fmt;
pub const BASE_CARD_ERROR_CODE: i32 = 1000;
pub const BASE_BLACKJACK_ERROR_CODE: i32 = 2000;
pub const BASE_SOLITAIRE_ERROR_CODE: i32 = 3000;
pub const BASE_ROCK_PAPER_SCISSORS_ERROR_CODE: i32 = 4000;
pub const BASE_COIN_TOSS_ERROR_CODE: i32 = 5000;
pub const BASE_DECK_ERROR_CODE: i32 = 6000;
pub const BASE_SLOT_MACHINE_ERROR_CODE: i32 = 7000;
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct GenericError {
pub error_code: i32,
pub error_message: String,
}
impl fmt::Display for GenericError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Error ({}): {}", self.error_code, self.error_message)
}
}
pub trait ErrorCode: fmt::Debug {
fn error_code(&self) -> i32;
}
impl<E: ErrorCode> From<E> for GenericError {
fn from(err: E) -> Self {
Self {
error_code: err.error_code(),
error_message: format!("{:?}", err),
}
}
}