| 1 |
//! Invalid variant error |
| 2 |
|
| 3 |
use core::fmt; |
| 4 |
|
| 5 |
/// An error type indicating that a [`FromStr`](core::str::FromStr) call failed because the value |
| 6 |
/// was not a valid variant. |
| 7 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 8 |
pub struct InvalidVariant; |
| 9 |
|
| 10 |
impl fmt::Display for InvalidVariant { |
| 11 |
#[inline] |
| 12 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 13 |
write!(f, "value was not a valid variant") |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
impl core::error::Error for InvalidVariant {} |
| 18 |
|
| 19 |
impl From<InvalidVariant> for crate::Error { |
| 20 |
#[inline] |
| 21 |
fn from(err: InvalidVariant) -> Self { |
| 22 |
Self::InvalidVariant(err) |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
impl TryFrom<crate::Error> for InvalidVariant { |
| 27 |
type Error = crate::error::DifferentVariant; |
| 28 |
|
| 29 |
#[inline] |
| 30 |
fn try_from(err: crate::Error) -> Result<Self, Self::Error> { |
| 31 |
match err { |
| 32 |
crate::Error::InvalidVariant(err) => Ok(err), |
| 33 |
_ => Err(crate::error::DifferentVariant), |
| 34 |
} |
| 35 |
} |
| 36 |
} |