Skip to main content

qubit_redact/policy/field/
unknown_field_policy.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Fallback behavior for fields without an explicit policy rule.
9
10use super::Sensitivity;
11
12/// Determines how a policy handles a field with no matching rule.
13///
14/// The default leaves unknown fields visible.
15#[non_exhaustive]
16#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
17pub enum UnknownFieldPolicy {
18    /// Leaves values visible when no explicit rule classifies their field.
19    #[default]
20    PassThrough,
21    /// Applies the supplied sensitivity to every unclassified field.
22    Redact(
23        /// Sensitivity used as the fallback classification.
24        Sensitivity,
25    ),
26}
27
28impl UnknownFieldPolicy {
29    /// Returns the sensitivity selected for an unclassified field.
30    ///
31    /// # Returns
32    ///
33    /// Some(level) when unknown fields must be redacted, or None when they
34    /// must remain visible.
35    #[must_use]
36    #[inline(always)]
37    pub const fn sensitivity(self) -> Option<Sensitivity> {
38        match self {
39            Self::PassThrough => None,
40            Self::Redact(level) => Some(level),
41        }
42    }
43}