fst_levenshtein/
error.rs

1use std::error;
2use std::fmt;
3
4/// An error that occurred while building a Levenshtein automaton.
5#[derive(Debug)]
6pub enum Error {
7    /// If construction of the automaton reaches some hard-coded limit
8    /// on the number of states, then this error is returned.
9    ///
10    /// The number given is the limit that was exceeded.
11    TooManyStates(usize),
12}
13
14impl fmt::Display for Error {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        use self::Error::*;
17        match *self {
18            TooManyStates(size_limit) => write!(
19                f,
20                "Levenshtein automaton exceeds size limit of \
21                           {} states",
22                size_limit
23            ),
24        }
25    }
26}
27
28impl error::Error for Error {
29    fn description(&self) -> &str {
30        use self::Error::*;
31        match *self {
32            TooManyStates(_) => "levenshtein automaton has too many states",
33        }
34    }
35
36    fn cause(&self) -> Option<&dyn error::Error> {
37        None
38    }
39}