qubit_redact/policy/allow_rule.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//! Read-only views of configured allow rules.
9
10use super::FieldNameMatching;
11
12/// A borrowed canonical field name and the breadth of its allow rule.
13///
14/// # Type Parameters
15///
16/// * `'a` - Lifetime of the borrowed canonical field name.
17#[must_use]
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct AllowRule<'a> {
20 /// Canonical field name.
21 field: &'a str,
22 /// Whether the rule applies exactly or at token suffix boundaries.
23 matching: FieldNameMatching,
24}
25
26impl<'a> AllowRule<'a> {
27 /// Creates a borrowed allow-rule view.
28 ///
29 /// # Parameters
30 ///
31 /// * `field` - Canonical field name.
32 /// * `matching` - Breadth of the allow rule.
33 ///
34 /// # Returns
35 ///
36 /// A read-only view over the supplied rule.
37 pub(super) const fn new(
38 field: &'a str,
39 matching: FieldNameMatching,
40 ) -> Self {
41 Self { field, matching }
42 }
43
44 /// Returns the canonical field name.
45 ///
46 /// # Returns
47 ///
48 /// The canonical field name borrowed from the policy.
49 #[must_use]
50 #[inline(always)]
51 pub const fn field(&self) -> &'a str {
52 self.field
53 }
54
55 /// Returns the breadth of the allow rule.
56 ///
57 /// # Returns
58 ///
59 /// [`FieldNameMatching::Exact`] for an exact-only allow rule or
60 /// [`FieldNameMatching::ExactOrTokenSuffix`] for a suffix allow rule.
61 pub const fn matching(&self) -> FieldNameMatching {
62 self.matching
63 }
64}