jieba_rs/
errors.rs

1use std::{error, fmt, io};
2
3/// The Error type
4#[derive(Debug)]
5pub enum Error {
6    /// I/O errors
7    Io(io::Error),
8    /// Invalid entry in dictionary
9    InvalidDictEntry(String),
10}
11
12impl From<io::Error> for Error {
13    fn from(err: io::Error) -> Self {
14        Self::Io(err)
15    }
16}
17
18impl fmt::Display for Error {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match *self {
21            Error::Io(ref err) => err.fmt(f),
22            Error::InvalidDictEntry(ref err) => write!(f, "invalid dictionary entry: {}", err),
23        }
24    }
25}
26
27impl error::Error for Error {
28    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
29        match *self {
30            Error::Io(ref err) => Some(err),
31            Error::InvalidDictEntry(_) => None,
32        }
33    }
34}