Debian Codegraph @

third_party/rust/time/src/error/invalid_variant.rs

raw
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 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 impl std::error::Error for InvalidVariant {}
18
19 impl From<InvalidVariant> for crate::Error {
20 fn from(err: InvalidVariant) -> Self {
21 Self::InvalidVariant(err)
22 }
23 }
24
25 impl TryFrom<crate::Error> for InvalidVariant {
26 type Error = crate::error::DifferentVariant;
27
28 fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
29 match err {
30 crate::Error::InvalidVariant(err) => Ok(err),
31 _ => Err(crate::error::DifferentVariant),
32 }
33 }
34 }