use derive_more::{Display, From};
use crate::Rule;
pub type Result<T> = core::result::Result<T, Error>;
#[non_exhaustive]
#[derive(Debug, From, Display)]
pub enum Error {
#[display("invalid range \"[{start}-{end}]\": start greater than end")]
InvalidRangeReversed { start: u32, end: u32 },
#[display("integer value {_0} exceeds limits")]
TooLarge(u32),
#[display("hostlist is too large")]
HostlistTooLarge,
#[display("unexpected parser state while processing rule:\n{_0:?}")]
UnexpectedParserState(Rule),
#[display("invalid hostname: \"{_0}\"")]
InvalidHostname(String),
#[display("internal error: \"{_0}\"")]
Internal(String),
#[display("parse error:\n{_0}")]
ParseError(Box<pest::error::Error<Rule>>),
#[from]
#[display("integer parse error: {_0}")]
ParseIntError(std::num::ParseIntError),
}
impl std::error::Error for Error {}
impl From<pest::error::Error<Rule>> for Error {
fn from(err: pest::error::Error<Rule>) -> Self {
Self::ParseError(Box::new(err))
}
}