time/error/
try_from_parsed.rs1use core::fmt;
4
5use crate::error;
6
7#[non_exhaustive]
9#[allow(variant_size_differences, reason = "only triggers on some platforms")]
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum TryFromParsed {
12 InsufficientInformation,
15 ComponentRange(error::ComponentRange),
17}
18
19impl fmt::Display for TryFromParsed {
20 #[inline]
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::InsufficientInformation => f.write_str(
24 "the `Parsed` struct did not include enough information to construct the type",
25 ),
26 Self::ComponentRange(err) => err.fmt(f),
27 }
28 }
29}
30
31impl From<error::ComponentRange> for TryFromParsed {
32 #[inline]
33 fn from(v: error::ComponentRange) -> Self {
34 Self::ComponentRange(v)
35 }
36}
37
38impl TryFrom<TryFromParsed> for error::ComponentRange {
39 type Error = error::DifferentVariant;
40
41 #[inline]
42 fn try_from(err: TryFromParsed) -> Result<Self, Self::Error> {
43 match err {
44 TryFromParsed::ComponentRange(err) => Ok(err),
45 _ => Err(error::DifferentVariant),
46 }
47 }
48}
49
50impl core::error::Error for TryFromParsed {
51 #[inline]
52 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
53 match self {
54 Self::InsufficientInformation => None,
55 Self::ComponentRange(err) => Some(err),
56 }
57 }
58}
59
60impl From<TryFromParsed> for crate::Error {
61 #[inline]
62 fn from(original: TryFromParsed) -> Self {
63 Self::TryFromParsed(original)
64 }
65}
66
67impl TryFrom<crate::Error> for TryFromParsed {
68 type Error = error::DifferentVariant;
69
70 #[inline]
71 fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
72 match err {
73 crate::Error::TryFromParsed(err) => Ok(err),
74 _ => Err(error::DifferentVariant),
75 }
76 }
77}