Skip to main content

ParseError

Enum ParseError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source§

fn clone(&self) -> ParseError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ParseError

Source§

impl Debug for ParseError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ParseError

Source§

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.

Source§

impl Eq for ParseError

Source§

impl Error for ParseError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Hash for ParseError

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ParseError

Source§

fn eq(&self, other: &ParseError) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ParseError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.