use super::AllowRule;
use super::FieldMatchKind;
use super::SensitiveFieldRule;
use super::Sensitivity;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FieldClassification<'a> {
Sensitive {
rule: SensitiveFieldRule<'a>,
match_kind: FieldMatchKind,
},
Allowed {
rule: AllowRule<'a>,
match_kind: FieldMatchKind,
},
Unknown,
}
impl<'a> FieldClassification<'a> {
#[must_use]
pub const fn sensitivity(self) -> Option<Sensitivity> {
match self {
Self::Sensitive { rule, .. } => Some(rule.sensitivity()),
Self::Allowed { .. } | Self::Unknown => None,
}
}
#[must_use]
pub const fn matched_field(self) -> Option<&'a str> {
match self {
Self::Sensitive { rule, .. } => Some(rule.field()),
Self::Allowed { rule, .. } => Some(rule.field()),
Self::Unknown => None,
}
}
#[must_use]
pub const fn match_kind(self) -> Option<FieldMatchKind> {
match self {
Self::Sensitive { match_kind, .. } | Self::Allowed { match_kind, .. } => Some(match_kind),
Self::Unknown => None,
}
}
#[inline(always)]
#[must_use]
pub const fn is_allowed(self) -> bool {
matches!(self, Self::Allowed { .. })
}
#[inline(always)]
#[must_use]
pub const fn is_unknown(self) -> bool {
matches!(self, Self::Unknown)
}
}
#[cfg(test)]
mod tests {
use super::FieldClassification;
#[test]
fn unknown_predicates_are_mutually_exclusive() {
let classification = FieldClassification::Unknown;
assert!(!classification.is_allowed());
assert!(classification.is_unknown());
}
}