fst/
error.rs

1use std::fmt;
2use std::io;
3
4use crate::raw;
5
6/// A `Result` type alias for this crate's `Error` type.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// An error that encapsulates all possible errors in this crate.
10#[derive(Debug)]
11pub 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
19impl From<io::Error> for Error {
20    #[inline]
21    fn from(err: io::Error) -> Error {
22        Error::Io(err)
23    }
24}
25
26impl From<raw::Error> for Error {
27    #[inline]
28    fn from(err: raw::Error) -> Error {
29        Error::Fst(err)
30    }
31}
32
33impl 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
42impl 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}