use std::fmt;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum MatcherError {
AutomatonBuild {
reason: String,
},
InvalidProcessType {
bits: u8,
},
EmptyPatterns,
}
impl fmt::Display for MatcherError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::AutomatonBuild { reason } => write!(f, "automaton build failed: {reason}"),
Self::InvalidProcessType { bits } => write!(
f,
"invalid ProcessType bits: {bits:#04x} \
(only bits 0\u{2013}5 are defined; bits 6\u{2013}7 must be zero)"
),
Self::EmptyPatterns => write!(
f,
"empty pattern set: at least one scannable pattern is required"
),
}
}
}
impl std::error::Error for MatcherError {}
impl MatcherError {
pub(crate) fn automaton_build(source: impl fmt::Display) -> Self {
Self::AutomatonBuild {
reason: source.to_string(),
}
}
pub(crate) fn invalid_process_type(bits: u8) -> Self {
Self::InvalidProcessType { bits }
}
}