Skip to main content

qubit_redact/policy/
policy_location.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Location of a policy-building validation error.
9
10use std::fmt;
11
12/// Policy construction context where a validation error occurred.
13///
14/// # Examples
15///
16/// ```
17/// use qubit_redact::PolicyLocation;
18///
19/// assert_eq!(PolicyLocation::Rules.to_string(), "rules");
20/// ```
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22#[non_exhaustive]
23pub enum PolicyLocation {
24    /// Regular field-rule construction context.
25    Rules,
26    /// Floor construction context.
27    Floor,
28    /// HTTP header field rules in an HTTP policy builder.
29    HttpHeader,
30    /// HTTP query and form field rules in an HTTP policy builder.
31    HttpQuery,
32    /// HTTP body field rules in an HTTP policy builder.
33    HttpBody,
34    /// Shared HTTP masking policy.
35    HttpMasking,
36}
37
38impl fmt::Display for PolicyLocation {
39    /// Writes the stable lowercase label, propagating any destination formatter
40    /// error.
41    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
42        match self {
43            Self::Rules => formatter.write_str("rules"),
44            Self::Floor => formatter.write_str("floor"),
45            Self::HttpHeader => formatter.write_str("http header"),
46            Self::HttpQuery => formatter.write_str("http query"),
47            Self::HttpBody => formatter.write_str("http body"),
48            Self::HttpMasking => formatter.write_str("http masking"),
49        }
50    }
51}