tantivy_fst/
error.rs

1use crate::raw;
2use std::error;
3use std::fmt;
4use std::io;
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        use self::Error::*;
36        match *self {
37            Fst(ref err) => err.fmt(f),
38            Io(ref err) => err.fmt(f),
39        }
40    }
41}
42
43impl error::Error for Error {
44    fn cause(&self) -> Option<&dyn error::Error> {
45        use self::Error::*;
46        match *self {
47            Fst(ref err) => Some(err),
48            Io(ref err) => Some(err),
49        }
50    }
51}