1use std::error;
2use std::fmt;
3
4#[derive(Debug)]
5pub enum Error {
6 BadAction(String),
7 NotEnoughTiles,
8 InvalidWord(String),
9 StartingTileNotCovered,
10 WordDoesNotIntersect,
11 NoLettersUsed,
12}
13
14impl fmt::Display for Error {
15 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16 match *self {
17 Error::BadAction(ref err) => write!(f, "Bad Action error: {}", err),
18 Error::NotEnoughTiles => write!(f, "Not enough tiles"),
19 Error::InvalidWord(ref word) => write!(f, "Word <{}> not in the dictionary", word),
20 Error::StartingTileNotCovered => write!(f, "Starting tile needs to be covered"),
21 Error::WordDoesNotIntersect => write!(f, "Word does not intersect with another word"),
22 Error::NoLettersUsed => write!(f, "You must use at least one letter"),
23 }
24 }
25}
26
27impl error::Error for Error {
28 fn cause(&self) -> Option<&dyn error::Error> {
29 Some(self)
30 }
31}
32
33pub type Result<T> = std::result::Result<T, Box<Error>>;