tzif/
error.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5use std::fmt;
6
7/// An error enum for all error types.
8#[derive(Debug)]
9pub enum Error {
10    /// A [`std::io::Error`].
11    Io(std::io::Error),
12    /// A [`combine::stream::read::Error`].
13    Read(combine::stream::read::Error),
14    /// A [`combine::error::UnexpectedParse`].
15    Parse(combine::error::UnexpectedParse),
16}
17
18impl From<std::io::Error> for Error {
19    fn from(err: std::io::Error) -> Self {
20        Error::Io(err)
21    }
22}
23
24impl From<combine::stream::read::Error> for Error {
25    fn from(err: combine::stream::read::Error) -> Self {
26        Error::Read(err)
27    }
28}
29
30impl From<combine::error::UnexpectedParse> for Error {
31    fn from(err: combine::error::UnexpectedParse) -> Self {
32        Error::Parse(err)
33    }
34}
35
36impl fmt::Display for Error {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Error::Io(err) => write!(f, "{err}"),
40            Error::Read(err) => write!(f, "{err}"),
41            Error::Parse(err) => write!(f, "{err}"),
42        }
43    }
44}
45
46impl std::error::Error for Error {}