tools_2048/
error.rs

1//! A module that contains the Error enum.
2
3use std::fmt::{self, Display, Formatter};
4
5/// An enum that represents the possible errors that can occur in this crate.
6#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
7pub enum Error {
8    /// Invalid game size. Must be at least 4.
9    InvalidSize,
10    /// Invalid value in a board. Must be 0 or power of 2, starting from 2.
11    InvalidValue,
12    /// There is no valid move to make. The game is over.
13    NoValidMove,
14}
15impl Display for Error {
16    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
17        match self {
18            Error::InvalidSize => write!(f, "Invalid game size. Must be at least 4."),
19            Error::InvalidValue => write!(f, "Invalid value in a board. Must be 0 or power of 2, starting from 2."),
20            Error::NoValidMove => write!(f, "There is no valid move to make. The game is over."),
21        }
22    }
23}
24impl std::error::Error for Error {}