sashite-qi 0.1.0

Qi: an immutable, format-agnostic position model for two-player board games (chess, shogi, xiangqi, and beyond).
Documentation
//! The error type returned by fallible `Qi` operations.

/// An error from constructing or transforming a [`Qi`](crate::Qi) position.
///
/// Construction errors come from an invalid shape; transformation errors come
/// from an out-of-range index, an impossible hand removal, or a piece count that
/// would exceed the board.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Error {
    /// The shape had no dimensions.
    EmptyShape,
    /// The shape had more than [`MAX_DIMENSIONS`](crate::MAX_DIMENSIONS).
    TooManyDimensions,
    /// A dimension size was zero.
    DimensionTooSmall,
    /// A dimension size exceeded [`MAX_DIMENSION_SIZE`](crate::MAX_DIMENSION_SIZE).
    DimensionTooLarge,
    /// The total number of squares exceeded
    /// [`MAX_SQUARE_COUNT`](crate::MAX_SQUARE_COUNT).
    TooManySquares,
    /// A board index was not a valid square on this board.
    IndexOutOfRange,
    /// A hand removal asked to remove more copies of a piece than were held.
    HandUnderflow,
    /// The number of pieces (board plus both hands) would exceed the number of
    /// squares.
    TooManyPieces,
}

impl core::fmt::Display for Error {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let message = match self {
            Self::EmptyShape => "shape must have at least one dimension",
            Self::TooManyDimensions => "shape exceeds the maximum number of dimensions",
            Self::DimensionTooSmall => "a dimension size must be at least 1",
            Self::DimensionTooLarge => "a dimension size exceeds the maximum",
            Self::TooManySquares => "the board exceeds the maximum number of squares",
            Self::IndexOutOfRange => "a board index is out of range",
            Self::HandUnderflow => "cannot remove a piece that is not in the hand",
            Self::TooManyPieces => "the number of pieces exceeds the number of squares",
        };
        f.write_str(message)
    }
}

impl core::error::Error for Error {}