domino_lib/types/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#[derive(Debug)]
pub enum DominoError {
    InvalidLength,
    UnsolvablePuzzle,
    NotValidPuzzle,
    Timeout
}

impl std::fmt::Display for DominoError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::InvalidLength => write!(f, "The puzzle length is not correct"),
            Self::UnsolvablePuzzle => write!(f, "The puzzle has no solutions"),
            Self::NotValidPuzzle => write!(f, "The puzzle is not valid/unique, it has multiple solutions"),
            Self::Timeout => write!(f, "The puzzle took too long to solve")
        }
    }
}

impl std::error::Error for DominoError {}

pub type Result<T, E = DominoError> = std::result::Result<T, E>;