time/error/
different_variant.rs

1//! Different variant error
2
3use core::fmt;
4
5/// An error type indicating that a [`TryFrom`](core::convert::TryFrom) call failed because the
6/// original value was of a different variant.
7#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DifferentVariant {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f, "DifferentVariant")
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for DifferentVariant {
    #[inline]
    fn clone(&self) -> DifferentVariant { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DifferentVariant { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for DifferentVariant {
    #[inline]
    fn eq(&self, other: &DifferentVariant) -> bool { true }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DifferentVariant {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) -> () {}
}Eq)]
8pub struct DifferentVariant;
9
10impl fmt::Display for DifferentVariant {
11    #[inline]
12    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13        f.write_fmt(format_args!("value was of a different variant than required"))write!(f, "value was of a different variant than required")
14    }
15}
16
17impl core::error::Error for DifferentVariant {}
18
19impl From<DifferentVariant> for crate::Error {
20    #[inline]
21    fn from(err: DifferentVariant) -> Self {
22        Self::DifferentVariant(err)
23    }
24}
25
26impl TryFrom<crate::Error> for DifferentVariant {
27    type Error = Self;
28
29    #[inline]
30    fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
31        match err {
32            crate::Error::DifferentVariant(err) => Ok(err),
33            _ => Err(Self),
34        }
35    }
36}