1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#![cfg_attr(feature = "cargo-clippy", allow(needless_return))]
#![cfg_attr(not(test), warn(missing_docs))]
extern crate failure;
#[macro_use]
extern crate failure_derive;
#[cfg(test)]
extern crate regex;
pub mod decoder;
pub mod encoder;
mod state_tracker;
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Fail)]
pub enum Error {
#[fail(display = "Saw the wrong type of token: {}", _0)]
InvalidState(String),
#[fail(display = "Keys were not sorted")]
UnsortedKeys,
#[fail(display = "Reached EOF in the middle of a message")]
UnexpectedEof,
#[fail(display = "Malformed number of unexpected character: {}", _0)]
SyntaxError(String),
#[fail(display = "Maximum nesting depth exceeded")]
NestingTooDeep,
}
impl Error {
fn unexpected(expected: &str, got: char, offset: usize) -> Self {
Error::SyntaxError(format!(
"Expected {}, got {:?} at offset {}",
expected, got, offset
))
}
fn invalid_state(expected: &str) -> Self {
Error::InvalidState(expected.to_owned())
}
}