time/error/
invalid_variant.rs

1//! Invalid variant error
2
3use 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)]
8pub struct InvalidVariant;
9
10impl fmt::Display for InvalidVariant {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        write!(f, "value was not a valid variant")
13    }
14}
15
16#[cfg(feature = "std")]
17#[allow(clippy::std_instead_of_core)]
18impl std::error::Error for InvalidVariant {}
19
20impl From<InvalidVariant> for crate::Error {
21    fn from(err: InvalidVariant) -> Self {
22        Self::InvalidVariant(err)
23    }
24}
25
26impl TryFrom<crate::Error> for InvalidVariant {
27    type Error = crate::error::DifferentVariant;
28
29    fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
30        match err {
31            crate::Error::InvalidVariant(err) => Ok(err),
32            _ => Err(crate::error::DifferentVariant),
33        }
34    }
35}