/rust/registry/src/index.crates.io-1949cf8c6b5b557f/fst-0.4.7/src/error.rs
Line | Count | Source |
1 | | use std::fmt; |
2 | | use std::io; |
3 | | |
4 | | use crate::raw; |
5 | | |
6 | | /// A `Result` type alias for this crate's `Error` type. |
7 | | pub type Result<T> = std::result::Result<T, Error>; |
8 | | |
9 | | /// An error that encapsulates all possible errors in this crate. |
10 | | #[derive(Debug)] |
11 | | pub enum Error { |
12 | | /// An error that occurred while reading or writing a finite state |
13 | | /// transducer. |
14 | | Fst(raw::Error), |
15 | | /// An IO error that occurred while writing a finite state transducer. |
16 | | Io(io::Error), |
17 | | } |
18 | | |
19 | | impl From<io::Error> for Error { |
20 | | #[inline] |
21 | 0 | fn from(err: io::Error) -> Error { |
22 | 0 | Error::Io(err) |
23 | 0 | } |
24 | | } |
25 | | |
26 | | impl From<raw::Error> for Error { |
27 | | #[inline] |
28 | 0 | fn from(err: raw::Error) -> Error { |
29 | 0 | Error::Fst(err) |
30 | 0 | } |
31 | | } |
32 | | |
33 | | impl fmt::Display for Error { |
34 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
35 | 0 | match *self { |
36 | 0 | Error::Fst(_) => write!(f, "FST error"), |
37 | 0 | Error::Io(_) => write!(f, "I/O error"), |
38 | | } |
39 | 0 | } |
40 | | } |
41 | | |
42 | | impl std::error::Error for Error { |
43 | 0 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
44 | 0 | match *self { |
45 | 0 | Error::Fst(ref err) => Some(err), |
46 | 0 | Error::Io(ref err) => Some(err), |
47 | | } |
48 | 0 | } |
49 | | } |