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///
16/// # Examples
17///
18/// ```
19/// use qubit_redact::{Sensitivity, UnknownFieldPolicy};
20///
21/// assert_eq!(UnknownFieldPolicy::default().sensitivity(), None);
22/// assert_eq!(UnknownFieldPolicy::Redact(Sensitivity::Secret).sensitivity(),
23/// Some(Sensitivity::Secret));
24/// ```
25#[non_exhaustive]
26#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
27pub enum UnknownFieldPolicy {
28 /// Leaves values visible when no explicit rule classifies their field.
29 #[default]
30 PassThrough,
31 /// Applies the supplied sensitivity to every unclassified field.
32 Redact(
33 /// Sensitivity used as the fallback classification.
34 Sensitivity,
35 ),
36}
37
38impl UnknownFieldPolicy {
39 /// Returns the sensitivity selected for an unclassified field.
40 ///
41 /// # Returns
42 ///
43 /// Some(level) when unknown fields must be redacted, or None when they
44 /// must remain visible.
45 #[must_use]
46 #[inline(always)]
47 pub const fn sensitivity(self) -> Option<Sensitivity> {
48 match self {
49 Self::PassThrough => None,
50 Self::Redact(level) => Some(level),
51 }
52 }
53}