| 1 |
use core::{error::Error, fmt}; |
| 2 |
|
| 3 |
/// Error of parsing an enum value its string representation. |
| 4 |
#[derive(Debug, Clone, Copy, Eq, PartialEq)] |
| 5 |
pub struct FromStrError { |
| 6 |
type_name: &'static str, |
| 7 |
} |
| 8 |
|
| 9 |
impl FromStrError { |
| 10 |
#[doc(hidden)] |
| 11 |
#[must_use] |
| 12 |
#[inline] |
| 13 |
pub const fn new(type_name: &'static str) -> Self { |
| 14 |
Self { type_name } |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
impl fmt::Display for FromStrError { |
| 19 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 20 |
write!(f, "Invalid `{}` string representation", self.type_name) |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
impl Error for FromStrError {} |