serde_types/parsing/
errors.rs1use super::*;
2use std::{error::Error, fmt::Display, num::ParseIntError, str::ParseBoolError};
3
4impl Debug for ParsableError {
5 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
6 f.debug_tuple("ParsableError").field(&self.message).finish()
7 }
8}
9
10impl Display for ParsableError {
11 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
12 f.write_str(&self.message)
13 }
14}
15
16impl Error for ParsableError {
17 fn source(&self) -> Option<&(dyn Error + 'static)> {
18 todo!()
19 }
20}
21
22impl serde::de::Error for ParsableError {
23 fn custom<T>(msg: T) -> Self
24 where
25 T: Display,
26 {
27 Self { message: msg.to_string(), source: None }
28 }
29}
30
31impl From<&str> for ParsableError {
32 fn from(value: &str) -> Self {
33 Self { message: value.to_string(), source: None }
34 }
35}
36
37impl From<ParseIntError> for ParsableError {
38 fn from(value: ParseIntError) -> Self {
39 Self { message: value.to_string(), source: Some(Box::new(value)) }
40 }
41}
42
43impl From<ParseBoolError> for ParsableError {
44 fn from(value: ParseBoolError) -> Self {
45 Self { message: value.to_string(), source: Some(Box::new(value)) }
46 }
47}