xavier_internal/deserialize/
error.rs1use std::{error, fmt};
2use std::char::ParseCharError;
3use std::convert::Infallible;
4use std::num::{ParseFloatError, ParseIntError};
5use std::str::ParseBoolError;
6use std::string::FromUtf8Error;
7use quick_xml::events::attributes::AttrError;
8
9#[derive(Debug)]
10pub struct PError {
11 message: String,
12}
13
14impl PError {
15 pub fn new(message: &str) -> Self {
16 PError {
17 message: message.to_string(),
18 }
19 }
20}
21
22impl fmt::Display for PError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 write!(f, "{}", self.message)
25 }
26}
27
28impl error::Error for PError {}
29
30impl From<FromUtf8Error> for PError {
31 fn from(value: FromUtf8Error) -> Self {
32 PError { message: value.to_string() }
33 }
34}
35
36impl From<quick_xml::Error> for PError {
37 fn from(value: quick_xml::Error) -> Self {
38 PError { message: value.to_string() }
39 }
40}
41
42impl From<AttrError> for PError {
43 fn from(value: AttrError) -> Self {
44 PError { message: value.to_string() }
45 }
46}
47
48impl From<ParseIntError> for PError {
49 fn from(value: ParseIntError) -> Self {
50 PError { message: value.to_string() }
51 }
52}
53
54impl From<ParseFloatError> for PError {
55 fn from(value: ParseFloatError) -> Self {
56 PError { message: value.to_string() }
57 }
58}
59
60impl From<ParseBoolError> for PError {
61 fn from(value: ParseBoolError) -> Self {
62 PError { message: value.to_string() }
63 }
64}
65
66impl From<ParseCharError> for PError {
67 fn from(value: ParseCharError) -> Self {
68 PError { message: value.to_string() }
69 }
70}
71
72impl From<Infallible> for PError {
73 fn from(value: Infallible) -> Self {
74 PError { message: value.to_string() }
75 }
76}
77
78impl From<&AttrError> for PError {
79 fn from(attr_error: &AttrError) -> Self {
80 PError { message: attr_error.to_string() }
81 }
82}
83
84impl From<()> for PError {
85 fn from(_error: ()) -> Self {
86 PError { message: "Unit Error".to_string() }
87 }
88}