derive_more/
str.rs

1use core::fmt;
2
3/// Error of parsing an enum value its string representation.
4#[derive(Debug, Clone, Copy, Eq, PartialEq)]
5pub struct FromStrError {
6    type_name: &'static str,
7}
8
9impl 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
18impl 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#[cfg(feature = "std")]
25impl std::error::Error for FromStrError {}