48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
use std::convert::From;
|
|
|
|
pub use lazy_static::lazy_static;
|
|
|
|
#[derive(Debug)]
|
|
pub enum ParseError {
|
|
ConformanceError,
|
|
IO(std::io::Error),
|
|
Preserves(preserves::error::Error),
|
|
}
|
|
|
|
const INPUT_NOT_CONFORMANT: &str = "Input not conformant with Schema";
|
|
|
|
impl std::fmt::Display for ParseError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
|
match self {
|
|
ParseError::ConformanceError => write!(f, "{}", INPUT_NOT_CONFORMANT),
|
|
ParseError::IO(e) => e.fmt(f),
|
|
ParseError::Preserves(e) => e.fmt(f),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for ParseError {}
|
|
|
|
impl From<std::io::Error> for ParseError {
|
|
fn from(v: std::io::Error) -> Self {
|
|
ParseError::IO(v)
|
|
}
|
|
}
|
|
|
|
impl From<preserves::error::Error> for ParseError {
|
|
fn from(v: preserves::error::Error) -> Self {
|
|
ParseError::Preserves(v)
|
|
}
|
|
}
|
|
|
|
impl From<ParseError> for std::io::Error {
|
|
fn from(v: ParseError) -> Self {
|
|
match v {
|
|
ParseError::ConformanceError =>
|
|
std::io::Error::new(std::io::ErrorKind::InvalidData, INPUT_NOT_CONFORMANT),
|
|
ParseError::IO(e) => e,
|
|
ParseError::Preserves(e) => e.into(),
|
|
}
|
|
}
|
|
}
|