Skip to main content

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