tinystr_raw/
error.rs

1use core::fmt;
2
3#[cfg(feature = "std")]
4use std::error;
5
6/// Enum to store the various types of errors that can cause parsing a TinyStr to fail.
7#[derive(PartialEq, Eq, Debug)]
8pub enum Error {
9    /// String is too large or too small to store as TinyStr.
10    InvalidSize,
11    /// String is empty.
12    InvalidNull,
13    /// String contains non-ASCII character(s).
14    NonAscii,
15}
16
17impl fmt::Display for Error {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Error::InvalidSize => write!(f, "invalid size"),
21            Error::InvalidNull => write!(f, "string is empty"),
22            Error::NonAscii => write!(f, "contains non-ASCII"),
23        }
24    }
25}
26
27#[cfg(feature = "std")]
28impl error::Error for Error {}