use std::sync::Arc;
use super::FieldNameMatching;
use super::RedactionFloor;
use super::SensitiveFieldPreset;
use super::Sensitivity;
use super::UnknownFieldPolicy;
use crate::policy::PolicyError;
use crate::policy::PolicyLocation;
use crate::policy::RedactionRulesBuilder;
#[derive(Debug, Clone)]
pub struct RedactionFloorBuilder {
rules: RedactionRulesBuilder,
}
impl RedactionFloorBuilder {
#[must_use]
#[inline(always)]
pub(super) fn empty() -> Self {
Self {
rules: RedactionRulesBuilder::empty(PolicyLocation::Floor),
}
}
#[must_use]
#[inline(always)]
pub(super) fn from_floor(floor: &RedactionFloor) -> Self {
Self {
rules: RedactionRulesBuilder::from_inner(&floor.inner, PolicyLocation::Floor),
}
}
#[must_use]
#[inline(always)]
pub fn matching(mut self, matching: FieldNameMatching) -> Self {
self.rules.matching(matching);
self
}
#[must_use]
#[inline(always)]
pub fn unknown_field_policy(mut self, policy: UnknownFieldPolicy) -> Self {
self.rules.unknown_field_policy(policy);
self
}
#[must_use]
#[inline(always)]
pub fn include_preset(mut self, preset: SensitiveFieldPreset) -> Self {
self.rules.include_preset(preset);
self
}
pub fn raise(mut self, field: &str, level: Sensitivity) -> Result<Self, PolicyError> {
self.rules.raise(field, level)?;
Ok(self)
}
pub fn build(self) -> Result<RedactionFloor, PolicyError> {
let inner = self.rules.build_inner()?;
Ok(RedactionFloor { inner: Arc::new(inner) })
}
}