#[non_exhaustive]pub enum ParseError {
Empty,
TooLong,
InvalidLetter,
}Expand description
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.
§Length is measured in bytes
A valid token is one ASCII letter, which is always exactly one byte, so the
parser can decide on the byte length before looking at any content. The
consequence is worth knowing when reading the variant back: an input of one
character that occupies several bytes — any non-ASCII character, such as
é — is reported as TooLong, not as
InvalidLetter. Both say “this is not a token”, and
the specification requires only that such input be rejected; only the
reported reason differs.
The rule is exact: InvalidLetter means the input
was one byte that was not an ASCII letter, and TooLong
means it was two bytes or more.
§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));
// One character, two bytes: rejected as too long.
assert_eq!("é".chars().count(), 1);
assert_eq!("é".parse::<Identifier>(), Err(ParseError::TooLong));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Empty
The input was empty.
TooLong
The input was two bytes or more, and a token is exactly one.
Because the check counts bytes, this also covers an input of a single non-ASCII character; see the note on the enum itself.
InvalidLetter
The input was a single byte that was not an ASCII letter.
Trait Implementations§
Source§impl Clone for ParseError
impl Clone for ParseError
Source§fn clone(&self) -> ParseError
fn clone(&self) -> ParseError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ParseError
Source§impl Debug for ParseError
impl Debug for ParseError
Source§impl Display for ParseError
impl Display for ParseError
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a short, human-readable reason.
The message goes out through core::fmt::Formatter::pad, so width,
fill, alignment and precision behave as they do for the equivalent
str; writing it straight to the buffer would silently discard those
options when a caller lines errors up in a column.
impl Eq for ParseError
Source§impl Error for ParseError
impl Error for ParseError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()