use board::{row, col, block};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct InvalidEntry {
pub cell: u8,
pub ch: char,
}
impl InvalidEntry {
#[inline]
pub fn row(self) -> u8 {
row(self.cell)
}
#[inline]
pub fn col(self) -> u8 {
col(self.cell)
}
#[inline]
pub fn block(self) -> u8 {
block(self.cell)
}
}
use std::fmt;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct NotEnoughRows(pub u8);
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum BlockParseError {
InvalidEntry(InvalidEntry),
InvalidLineLength(u8),
NotEnoughRows(u8),
IncorrectFieldDelimiter,
TooManyRows,
MissingCommentDelimiter(u8),
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum LineParseError {
InvalidEntry(InvalidEntry),
NotEnoughCells(u8),
TooManyCells,
MissingCommentDelimiter,
}
impl fmt::Display for LineParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::LineParseError as Error;
match *self {
Error::InvalidEntry(InvalidEntry { cell, ch }) => {
write!(f, "cell {} contains invalid character '{}'", cell, ch)
}
Error::NotEnoughCells(cells) => write!(f, "sudoku contains {} cells instead of required 81", cells),
Error::TooManyCells => write!(
f,
"sudoku contains more than 81 cells or is missing comment delimiter"
),
Error::MissingCommentDelimiter => write!(f, "missing comment delimiter"),
}
}
}