qubit_redact/facade/redaction_reasons.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//! Compact sets of redaction degradation reasons.
9
10use super::RedactionReason;
11
12/// Compact set of summary reasons.
13///
14/// # Examples
15///
16/// ```
17/// use qubit_redact::RedactionReason;
18/// use qubit_redact::RedactionReasons;
19///
20/// let reasons = RedactionReasons::empty().with(RedactionReason::InputLimitReached);
21/// assert!(reasons.contains(RedactionReason::InputLimitReached));
22/// assert!(!reasons.contains(RedactionReason::OutputLimitReached));
23/// ```
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
25pub struct RedactionReasons(
26 /// Stable bit flags for the reasons accumulated by one operation.
27 u64,
28);
29
30impl RedactionReasons {
31 /// Creates an empty reason set.
32 ///
33 /// # Returns
34 ///
35 /// A set containing no degradation reasons.
36 #[must_use]
37 #[inline(always)]
38 pub const fn empty() -> Self {
39 Self(0)
40 }
41
42 /// Returns whether a reason is present.
43 ///
44 /// # Parameters
45 ///
46 /// - `reason`: Degradation reason whose membership is queried.
47 ///
48 /// # Returns
49 ///
50 /// True exactly when this set contains the requested reason.
51 #[must_use]
52 #[inline(always)]
53 pub const fn contains(self, reason: RedactionReason) -> bool {
54 self.0 & reason.bit() != 0
55 }
56
57 /// Adds one reason.
58 ///
59 /// # Parameters
60 ///
61 /// - `reason`: Degradation reason to insert.
62 ///
63 /// # Returns
64 ///
65 /// A copy of this set containing the supplied reason.
66 #[must_use]
67 #[inline(always)]
68 pub const fn with(self, reason: RedactionReason) -> Self {
69 Self(self.0 | reason.bit())
70 }
71
72 /// Combines two reason sets.
73 ///
74 /// # Parameters
75 ///
76 /// - `other`: Additional degradation reasons to combine.
77 ///
78 /// # Returns
79 ///
80 /// A set containing every reason present in either operand.
81 #[must_use]
82 #[inline(always)]
83 pub const fn union(self, other: Self) -> Self {
84 Self(self.0 | other.0)
85 }
86}