use alloc::string::{String, ToString};
use thiserror::Error;
pub type Result<T, E = Error> = core::result::Result<T, E>;
#[derive(Debug, Error, PartialEq)]
pub enum Error {
#[error("{0:?}")]
Pest(PestErrorFormatter),
#[error("Rule error: {0}")]
Rule(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Parse error: {0}")]
Parse(String),
#[error("Preprocess error: {0}")]
Preprocess(String),
}
#[derive(PartialEq)]
pub struct PestErrorFormatter(String);
impl core::fmt::Debug for PestErrorFormatter {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<pest::error::Error<crate::Rule>> for Error {
fn from(e: pest::error::Error<crate::Rule>) -> Self {
Error::Pest(PestErrorFormatter(e.to_string()))
}
}