time/error/
parse_from_description.rs1use core::fmt;
4
5use crate::error;
6
7#[non_exhaustive]
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum ParseFromDescription {
11 #[non_exhaustive]
13 InvalidLiteral,
14 InvalidComponent(&'static str),
16 #[non_exhaustive]
18 UnexpectedTrailingCharacters,
19}
20
21impl fmt::Display for ParseFromDescription {
22 #[inline]
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 Self::InvalidLiteral => f.write_str("a character literal was not valid"),
26 Self::InvalidComponent(name) => {
27 write!(f, "the '{name}' component could not be parsed")
28 }
29 Self::UnexpectedTrailingCharacters => {
30 f.write_str("unexpected trailing characters; the end of input was expected")
31 }
32 }
33 }
34}
35
36impl core::error::Error for ParseFromDescription {}
37
38impl From<ParseFromDescription> for crate::Error {
39 #[inline]
40 fn from(original: ParseFromDescription) -> Self {
41 Self::ParseFromDescription(original)
42 }
43}
44
45impl TryFrom<crate::Error> for ParseFromDescription {
46 type Error = error::DifferentVariant;
47
48 #[inline]
49 fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
50 match err {
51 crate::Error::ParseFromDescription(err) => Ok(err),
52 _ => Err(error::DifferentVariant),
53 }
54 }
55}