games/solitaire/
errors.rs1pub type SError<T> = Result<T, SolitaireError>;
3
4use crate::errors::{BASE_SOLITAIRE_ERROR_CODE, ErrorCode};
5use core::fmt::{self, Display};
6
7#[repr(C)]
9#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize, Hash, PartialEq, Eq)]
10pub enum SolitaireError {
11 IllegalMovementError,
13 OutOfRangeError,
15 OutOfCardsError,
17 OutOfMoves,
19}
20
21impl Display for SolitaireError {
22 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23 use SolitaireError::*;
24 match *self {
25 IllegalMovementError => f.write_str("Illegal Movement"),
26 OutOfRangeError => {
27 f.write_str("Requested movement extends beyond any position cards lay")
28 }
29 OutOfCardsError => f.write_str("Out of cards"),
30 OutOfMoves => f.write_str("Out of moves"),
31 }
32 }
33}
34
35impl ErrorCode for SolitaireError {
36 fn error_code(&self) -> i32 {
37 BASE_SOLITAIRE_ERROR_CODE
38 + match *self {
39 SolitaireError::IllegalMovementError => 1,
40 SolitaireError::OutOfRangeError => 2,
41 SolitaireError::OutOfCardsError => 3,
42 SolitaireError::OutOfMoves => 4,
43 }
44 }
45}