#[cfg(doc)]
use crate::Sudoku;
#[derive(Debug, thiserror::Error)]
#[error("byte array contains entries >9")]
pub struct FromBytesError(pub(crate) ());
#[derive(Debug, thiserror::Error)]
pub enum FromBytesSliceError {
#[error("byte slice should have length 81, found {0}")]
WrongLength(usize),
#[error(transparent)]
FromBytesError(FromBytesError),
}
use crate::board::{block, col, row};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, thiserror::Error)]
#[error("cell {cell} contains invalid character '{ch}'")]
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)
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
#[error("input ended after {0} valid rows")]
pub struct NotEnoughRows(pub u8);
#[derive(Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
pub enum BlockParseError {
#[error(transparent)]
InvalidEntry(InvalidEntry),
#[error("a sudoku line should have 9 entries, found {0}")]
InvalidLineLength(u8),
#[error("a sudoku should have 9 rows, found only {0}")]
NotEnoughRows(u8),
#[error("inconsistent field delimiters")]
IncorrectFieldDelimiter,
#[error("a sudoku should have 9 rows, found a 10th")]
TooManyRows,
#[error("missing comment delimiter in line {0}")]
MissingCommentDelimiter(u8),
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
pub enum LineParseError {
#[error(transparent)]
InvalidEntry(InvalidEntry),
#[error("sudoku contains {0} cells instead of required 81")]
NotEnoughCells(u8),
#[error("sudoku contains more than 81 cells or is missing comment delimiter")]
TooManyCells,
#[error("missing comment delimiter")]
MissingCommentDelimiter,
}