use std::error;
use std::fmt;
use regex_syntax;
#[derive(Debug)]
pub enum Error {
Syntax(regex_syntax::Error),
CompiledTooBig(usize),
TooManyStates(usize),
NoLazy,
NoWordBoundary,
NoEmpty,
NoBytes,
}
impl From<regex_syntax::Error> for Error {
#[inline]
fn from(err: regex_syntax::Error) -> Error {
Error::Syntax(err)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::Error::*;
match *self {
Syntax(ref err) => err.fmt(f),
CompiledTooBig(size_limit) => write!(
f,
"Compiled regex exceeds size limit of {} bytes",
size_limit
),
TooManyStates(size_limit) => write!(
f,
"Compiled regex exceeds size limit of {} states",
size_limit
),
NoLazy => write!(
f,
"Lazy reptition operators such as '+?' are \
not allowed."
),
NoWordBoundary => write!(
f,
"Word boundary operators are not \
allowed."
),
NoEmpty => write!(
f,
"Empty match operators are not allowed \
(hopefully temporary)."
),
NoBytes => write!(f, "Byte literals are not allowed."),
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
use self::Error::*;
match *self {
Syntax(ref err) => Some(err),
_ => None,
}
}
}