use crate::PolicyError;
use crate::PolicyLocation;
use crate::RedactionFloor;
use crate::RedactionRules;
use crate::policy::RedactionRulesBuilder;
#[derive(Debug, Clone)]
pub(super) struct ContextRulesBuilder {
pub(super) rules: RedactionRulesBuilder,
pub(super) floor: Option<RedactionFloor>,
}
impl ContextRulesBuilder {
#[must_use]
#[inline]
pub(super) fn empty(location: PolicyLocation) -> Self {
Self {
rules: RedactionRulesBuilder::empty(location),
floor: None,
}
}
#[must_use]
#[inline]
pub(super) fn from_rules(rules: &RedactionRules, location: PolicyLocation) -> Self {
Self {
rules: RedactionRulesBuilder::from_inner(&rules.clone_application(), location),
floor: rules.floor().cloned(),
}
}
#[inline]
pub(super) fn with_floor(&mut self, floor: RedactionFloor) {
self.floor = Some(floor);
}
#[inline(always)]
pub(super) fn disable_floor(&mut self) {
self.floor = None;
}
#[inline]
pub(super) fn build(self) -> Result<RedactionRules, PolicyError> {
Ok(RedactionRules::new(self.rules.build_inner()?, self.floor))
}
}