sashite-sin 1.0.0

Style Identifier Notation (SIN): a compact, ASCII-only, no_std token encoding a player's side and style in abstract strategy board games.
Documentation
//! Errors produced when parsing a SIN token.

/// The reason a string could not be parsed as a SIN token.
///
/// Returned by the parsing entry points ([`crate::Identifier::parse`],
/// [`core::str::FromStr`], [`TryFrom`]) and by [`crate::Letter::try_from_char`].
///
/// This enum is `#[non_exhaustive]`: future revisions may add variants without
/// a breaking change, so downstream `match` expressions should include a
/// wildcard arm.
///
/// # Examples
///
/// ```
/// use sashite_sin::{Identifier, ParseError};
///
/// assert_eq!("".parse::<Identifier>(), Err(ParseError::Empty));
/// assert_eq!("CC".parse::<Identifier>(), Err(ParseError::TooLong));
/// assert_eq!("1".parse::<Identifier>(), Err(ParseError::InvalidLetter));
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ParseError {
    /// The input was empty.
    Empty,
    /// The input was longer than the single character a token occupies.
    TooLong,
    /// The input was not a single ASCII letter.
    InvalidLetter,
}

impl core::fmt::Display for ParseError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let message = match self {
            Self::Empty => "empty SIN token",
            Self::TooLong => "SIN token longer than one character",
            Self::InvalidLetter => "SIN token must contain exactly one ASCII letter",
        };
        f.write_str(message)
    }
}

impl core::error::Error for ParseError {}