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