wjp/
error.rs

1use std::fmt::{Debug, Error, Formatter};
2
3/// Error Struct that contains different Information's on what went wrong
4#[derive(Eq, PartialOrd, PartialEq, Hash, Clone, Default, Ord)]
5pub struct ParseError(String);
6
7impl ParseError {
8    /// constructs a new ParseError with an empty message
9    pub const fn new() -> Self {
10        Self(String::new())
11    }
12    /// replaces the Error Message with a provided Message
13    pub fn with_msg(mut self, msg: &str) -> Self {
14        self.0 = String::from(msg);
15        self
16    }
17}
18
19impl From<Error> for ParseError {
20    fn from(value: Error) -> Self {
21        ParseError::from(value.to_string())
22    }
23}
24
25impl From<()> for ParseError {
26    fn from(_value: ()) -> Self {
27        Self::new()
28    }
29}
30impl From<String> for ParseError {
31    fn from(value: String) -> Self {
32        ParseError(value)
33    }
34}
35
36impl Debug for ParseError {
37    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
38        write!(f, "{}", self.0)
39    }
40}