mago_php_version/
error.rs

1use std::error::Error;
2use std::num::ParseIntError;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum ParsingError {
6    InvalidFormat,
7    ParseIntError(ParseIntError),
8}
9
10impl std::fmt::Display for ParsingError {
11    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
12        match self {
13            Self::InvalidFormat => write!(f, "Invalid version format, expected 'major.minor.patch'."),
14            Self::ParseIntError(e) => write!(f, "Failed to parse integer component of version: {e}."),
15        }
16    }
17}
18
19impl Error for ParsingError {
20    fn source(&self) -> Option<&(dyn Error + 'static)> {
21        match self {
22            Self::ParseIntError(e) => Some(e),
23            _ => None,
24        }
25    }
26}
27
28impl From<ParseIntError> for ParsingError {
29    fn from(e: ParseIntError) -> Self {
30        Self::ParseIntError(e)
31    }
32}