#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ParseError {
InputTooLong,
NonAscii,
FieldCount,
PlacementEmpty,
PlacementStartsWithSeparator,
PlacementEndsWithSeparator,
EmptySegment,
InvalidEmptyCount,
InvalidPieceToken,
BoardNotRegular,
DimensionalCoherence,
TooManyDimensions,
DimensionTooLarge,
InvalidHandsDelimiter,
InvalidHandCount,
HandNotAggregated,
HandNotCanonical,
InvalidStyleTurnDelimiter,
InvalidStyleToken,
StylesSameCase,
TooManySquares,
TooManyPieces,
}
impl core::fmt::Display for ParseError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let message = match self {
Self::InputTooLong => "FEEN string exceeds the maximum length",
Self::NonAscii => "FEEN string contains a non-ASCII byte",
Self::FieldCount => "FEEN string must have exactly three space-separated fields",
Self::PlacementEmpty => "the piece-placement field is empty",
Self::PlacementStartsWithSeparator => {
"the piece-placement field must not start with '/'"
}
Self::PlacementEndsWithSeparator => "the piece-placement field must not end with '/'",
Self::EmptySegment => "the piece-placement field has an empty segment",
Self::InvalidEmptyCount => "an empty-count is zero or has a leading zero",
Self::InvalidPieceToken => "the piece-placement field contains an invalid piece token",
Self::BoardNotRegular => "the board is not regular (ranks of differing sizes)",
Self::DimensionalCoherence => "the board violates dimensional coherence",
Self::TooManyDimensions => "the board has too many dimensions",
Self::DimensionTooLarge => "a board dimension exceeds the maximum size",
Self::InvalidHandsDelimiter => "the hands field must contain exactly one '/'",
Self::InvalidHandCount => "a hand multiplicity is 0, 1, or has a leading zero",
Self::HandNotAggregated => "identical hand pieces are not aggregated",
Self::HandNotCanonical => "hand items are not in canonical order",
Self::InvalidStyleTurnDelimiter => "the style-turn field must contain exactly one '/'",
Self::InvalidStyleToken => "the style-turn field contains an invalid style token",
Self::StylesSameCase => "the two style tokens must be of opposite case",
Self::TooManySquares => "the board has more squares than the maximum",
Self::TooManyPieces => "the position has more pieces than squares",
};
f.write_str(message)
}
}
impl core::error::Error for ParseError {}