json_gettext/
json_get_text_build_errors.rs1use std::{
2 error::Error,
3 fmt::{Display, Error as FmtError, Formatter},
4 io,
5};
6
7use crate::{serde_json::Error as JSONError, Key};
8
9#[derive(Debug)]
10pub enum JSONGetTextBuildError {
11 DefaultKeyNotFound,
12 TextInKeyNotInDefaultKey { key: Key, text: String },
13 DuplicatedKey(Key),
14 IOError(io::Error),
15 SerdeJSONError(JSONError),
16}
17
18impl Display for JSONGetTextBuildError {
19 #[inline]
20 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
21 match self {
22 JSONGetTextBuildError::DefaultKeyNotFound => {
23 f.write_str("The default key is not found.")
24 },
25 JSONGetTextBuildError::TextInKeyNotInDefaultKey {
26 key,
27 text,
28 } => f.write_fmt(format_args!(
29 "The text `{}` in the key `{}` is not found in the default key.",
30 text, key
31 )),
32 JSONGetTextBuildError::DuplicatedKey(key) => Display::fmt(key, f),
33 JSONGetTextBuildError::IOError(err) => Display::fmt(err, f),
34 JSONGetTextBuildError::SerdeJSONError(err) => Display::fmt(err, f),
35 }
36 }
37}
38
39impl Error for JSONGetTextBuildError {}
40
41impl From<io::Error> for JSONGetTextBuildError {
42 #[inline]
43 fn from(v: io::Error) -> JSONGetTextBuildError {
44 JSONGetTextBuildError::IOError(v)
45 }
46}
47
48impl From<JSONError> for JSONGetTextBuildError {
49 #[inline]
50 fn from(v: JSONError) -> JSONGetTextBuildError {
51 JSONGetTextBuildError::SerdeJSONError(v)
52 }
53}