]> git.proxmox.com Git - rustc.git/blob - vendor/fst/src/error.rs
New upstream version 1.48.0+dfsg1
[rustc.git] / vendor / fst / src / error.rs
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 fn from(err: io::Error) -> Error {
22 Error::Io(err)
23 }
24 }
25
26 impl From<raw::Error> for Error {
27 #[inline]
28 fn from(err: raw::Error) -> Error {
29 Error::Fst(err)
30 }
31 }
32
33 impl fmt::Display for Error {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match *self {
36 Error::Fst(_) => write!(f, "FST error"),
37 Error::Io(_) => write!(f, "I/O error"),
38 }
39 }
40 }
41
42 impl std::error::Error for Error {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
44 match *self {
45 Error::Fst(ref err) => Some(err),
46 Error::Io(ref err) => Some(err),
47 }
48 }
49 }