diff --git a/engine/Cargo.toml b/engine/Cargo.toml index e83dd984..bef09b75 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -38,5 +38,5 @@ criterion.workspace = true indoc.workspace = true [features] -regex = ["dep:regex-automata"] default = [ "regex" ] +regex = ["dep:regex-automata"] diff --git a/engine/src/rhs_types/regex/imp_real.rs b/engine/src/rhs_types/regex/imp_real.rs index fbb87870..ebfa74f9 100644 --- a/engine/src/rhs_types/regex/imp_real.rs +++ b/engine/src/rhs_types/regex/imp_real.rs @@ -16,7 +16,7 @@ pub struct Regex { impl Regex { /// Retrieves the syntax configuration that will be used to build the regex. #[inline] - pub fn syntax_config() -> regex_automata::util::syntax::Config { + fn syntax_config() -> regex_automata::util::syntax::Config { regex_automata::util::syntax::Config::new() .unicode(false) .utf8(false) @@ -24,7 +24,7 @@ impl Regex { /// Retrieves the meta configuration that will be used to build the regex. #[inline] - pub fn meta_config(settings: &ParserSettings) -> regex_automata::meta::Config { + fn meta_config(settings: &ParserSettings) -> regex_automata::meta::Config { regex_automata::meta::Config::new() .match_kind(MatchKind::LeftmostFirst) .utf8_empty(false) @@ -56,7 +56,7 @@ impl Regex { } else if let Some(syntax) = err.syntax_error() { Error::Syntax(syntax.to_string()) } else { - unreachable!() + Error::Other(err.to_string()) } }) } diff --git a/engine/src/rhs_types/regex/mod.rs b/engine/src/rhs_types/regex/mod.rs index 804b749d..a25b7776 100644 --- a/engine/src/rhs_types/regex/mod.rs +++ b/engine/src/rhs_types/regex/mod.rs @@ -135,21 +135,15 @@ impl Serialize for Regex { #[derive(Clone, Debug, Error, PartialEq)] pub enum Error { /// A syntax error. + #[error("{0}")] Syntax(String), /// The compiled regex exceeded the configured /// regex compiled size limit. + #[error("Compiled regex exceeds size limit of {0} bytes.")] CompiledTooBig(usize), -} - -impl Display for Error { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match *self { - Error::Syntax(ref err) => Display::fmt(err, f), - Error::CompiledTooBig(limit) => { - write!(f, "Compiled regex exceeds size limit of {} bytes.", limit) - } - } - } + /// An uncategorized error. + #[error("{0}")] + Other(String), } #[cfg(test)]