use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum PrintingError {
#[error("Failed to create a grid as there were too many characters. Expected {}, got {}", .0.expected_character_count, .0.actual_character_count)]
TooManyCharacters(LengthErrorData),
#[error("Failed to create a grid as there weren't enough characters. Expected {}, got {}", .0.expected_character_count, .0.actual_character_count)]
TooLittleCharacters(LengthErrorData),
#[error("Failed to obtain the dimensions of the terminal. Reason: {}", .0)]
FailedToGetTerminalDimensions(String),
#[error("A grid larger than the terminal itself was passed in.")]
GridLargerThanTerminal,
#[error("A non rectangular grid was passed in.")]
NonRectangularGrid,
#[error("Failed to obtain the stored dimensions of the grid.")]
GridDimensionsNotDefined,
#[error("Failed to obtain the stored terminal dimensions.")]
TerminalDimensionsNotDefined,
#[error("Failed to obtain the stored origin position.")]
OriginNotDefined,
}
impl PartialEq for PrintingError {
fn eq(&self, other: &Self) -> bool {
std::mem::discriminant(self) == std::mem::discriminant(other)
}
}
impl Eq for PrintingError {}
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct LengthErrorData {
pub expected_character_count: usize,
pub actual_character_count: usize,
}
impl LengthErrorData {
pub(crate) fn new(expected_character_count: usize, actual_character_count: usize) -> Self {
Self {
expected_character_count,
actual_character_count,
}
}
}