Skip to main content

json_gettext/value/
errors.rs

1use std::{
2    error::Error,
3    fmt::{self, Display, Formatter},
4};
5
6use crate::serde_json::Error as JSONError;
7
8#[derive(Debug)]
9#[non_exhaustive]
10pub enum JSONGetTextValueError {
11    IntegerOutOfRange,
12    ParseError(JSONError),
13}
14
15impl Display for JSONGetTextValueError {
16    #[inline]
17    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
18        match self {
19            JSONGetTextValueError::IntegerOutOfRange => f.write_str("The integer is out of range."),
20            JSONGetTextValueError::ParseError(error) => Display::fmt(error, f),
21        }
22    }
23}
24
25impl Error for JSONGetTextValueError {
26    #[inline]
27    fn source(&self) -> Option<&(dyn Error + 'static)> {
28        match self {
29            JSONGetTextValueError::ParseError(err) => Some(err),
30            _ => None,
31        }
32    }
33}
34
35impl From<JSONError> for JSONGetTextValueError {
36    #[inline]
37    fn from(error: JSONError) -> JSONGetTextValueError {
38        JSONGetTextValueError::ParseError(error)
39    }
40}