pjson_parser/parser/
errors.rs

1use std::error::Error;
2use std::fmt;
3
4/// ParserError represents all the possible errors that can be gotten
5/// from parsing a JSON string.
6#[derive(Debug)]
7pub enum ParserError {
8  UnexpectedCharacterError(char, usize),
9  UnexpectedNumberError(usize),
10  UnexpectedEndError,
11}
12
13impl Error for ParserError {}
14
15impl fmt::Display for ParserError {
16  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17    match *self {
18      ParserError::UnexpectedCharacterError(c, p) => {
19        write!(f, "Unexpected character {} at position {}", c, p)
20      }
21      ParserError::UnexpectedNumberError(p) => write!(f, "Unexpected number at position {}", p),
22      ParserError::UnexpectedEndError => write!(f, "Unexpected end of JSON input"),
23    }
24  }
25}