fours 0.1.0

Four in a row in your terminal, with three levels of opponent.
Documentation
use crate::game::GameError;
use std::fmt;

/// The smallest number of columns or rows a board may have.
pub const MINIMUM_SIDE: usize = 1;

/// The largest number of columns or rows a board may have.
pub const MAXIMUM_SIDE: usize = 64;

/// The size of a board.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct BoardDimensions {
    column_count: usize,
    row_count: usize,
}

impl BoardDimensions {
    /// The size of a standard four in a row board: seven columns and six rows.
    pub const STANDARD: Self = Self {
        column_count: 7,
        row_count: 6,
    };

    /// Dimensions with the given number of columns and rows.
    ///
    /// # Errors
    ///
    /// Returns [`GameError::InvalidDimensions`] if either side is outside the range
    /// [`MINIMUM_SIDE`] to [`MAXIMUM_SIDE`].
    ///
    /// # Examples
    ///
    /// ```
    /// use fours::game::BoardDimensions;
    ///
    /// let dimensions = BoardDimensions::new(7, 6).unwrap();
    /// assert_eq!(dimensions, BoardDimensions::STANDARD);
    /// assert!(BoardDimensions::new(0, 6).is_err());
    /// ```
    pub const fn new(column_count: usize, row_count: usize) -> Result<Self, GameError> {
        if column_count < MINIMUM_SIDE
            || row_count < MINIMUM_SIDE
            || column_count > MAXIMUM_SIDE
            || row_count > MAXIMUM_SIDE
        {
            return Err(GameError::InvalidDimensions {
                column_count,
                row_count,
            });
        }

        Ok(Self {
            column_count,
            row_count,
        })
    }

    /// Dimensions that are already known to be valid, such as those of a board that exists.
    pub(crate) const fn from_counts(column_count: usize, row_count: usize) -> Self {
        Self {
            column_count,
            row_count,
        }
    }

    /// The number of columns of the board.
    pub const fn column_count(self) -> usize {
        self.column_count
    }

    /// The number of rows of the board.
    pub const fn row_count(self) -> usize {
        self.row_count
    }

    /// The number of cells of the board.
    pub const fn cell_count(self) -> usize {
        self.column_count * self.row_count
    }
}

impl Default for BoardDimensions {
    fn default() -> Self {
        Self::STANDARD
    }
}

impl fmt::Display for BoardDimensions {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(formatter, "{}x{}", self.column_count, self.row_count)
    }
}