mesh_portal_versions/
error.rs

1use std::convert::Infallible;
2use std::fmt::{Display, Formatter};
3use std::string::FromUtf8Error;
4
5use nom::error::VerboseError;
6use semver::{ReqParseError, SemVerError};
7use std::num::ParseIntError;
8
9#[derive(Debug,Eq,PartialEq)]
10pub struct Error {
11    pub message: String,
12}
13
14impl Display for Error {
15    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16        f.write_str(self.message.as_str())
17    }
18}
19
20impl std::error::Error for Error {}
21
22impl From<String> for Error {
23    fn from(message: String) -> Self {
24        Self { message }
25    }
26}
27
28impl From<FromUtf8Error> for Error {
29    fn from(message: FromUtf8Error) -> Self {
30        Self {
31            message: message.to_string(),
32        }
33    }
34}
35
36impl From<&str> for Error {
37    fn from(message: &str) -> Self {
38        Self {
39            message: message.to_string(),
40        }
41    }
42}
43
44impl From<Box<bincode::ErrorKind>> for Error {
45    fn from(message: Box<bincode::ErrorKind>) -> Self {
46        Self {
47            message: message.to_string(),
48        }
49    }
50}
51
52impl From<Infallible> for Error {
53    fn from(i: Infallible) -> Self {
54        Self {
55            message: i.to_string(),
56        }
57    }
58}
59
60impl From<nom::Err<VerboseError<&str>>> for Error {
61    fn from(error: nom::Err<VerboseError<&str>>) -> Self {
62        Self {
63            message: error.to_string()
64        }
65    }
66}
67
68impl From<ReqParseError> for Error {
69    fn from(error: ReqParseError) -> Self {
70        Self {
71            message: error.to_string()
72        }
73    }
74}
75
76impl From<SemVerError> for Error {
77    fn from(error: SemVerError) -> Self {
78        Self {
79            message: error.to_string()
80        }
81    }
82}
83
84impl From<strum::ParseError> for Error {
85    fn from(error: strum::ParseError) -> Self {
86        Self {
87            message: error.to_string()
88        }
89    }
90}
91
92impl From<ParseIntError> for Error {
93    fn from(x: ParseIntError) -> Self {
94        Self{
95            message: x.to_string()
96        }
97    }
98}
99
100impl From<regex::Error> for Error {
101    fn from(x: regex::Error) -> Self {
102        Self{
103            message: x.to_string()
104        }
105    }
106}