Skip to main content

qubit_redact/facade/
redaction_inspection_error.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//! Fail-closed error returned when inspection cannot classify complete input.
9
10use std::error::Error;
11use std::fmt;
12
13use super::RedactionReasons;
14use super::RedactionUsage;
15
16/// An inconclusive redaction inspection.
17///
18/// Callers must treat this error as potentially sensitive. The error exposes
19/// only bounded accounting and machine-readable reasons; it never retains the
20/// original input or a partial sensitivity result.
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct RedactionInspectionError {
23    /// Causes that prevented a conclusive classification.
24    reasons: RedactionReasons,
25    /// Resources consumed before inspection stopped.
26    usage: RedactionUsage,
27}
28
29impl RedactionInspectionError {
30    /// Creates an error from runtime-owned failure metadata.
31    #[must_use]
32    pub(crate) const fn new(reasons: RedactionReasons, usage: RedactionUsage) -> Self {
33        Self { reasons, usage }
34    }
35
36    /// Returns the machine-readable causes of incomplete inspection.
37    #[must_use]
38    #[inline(always)]
39    pub const fn reasons(&self) -> RedactionReasons {
40        self.reasons
41    }
42
43    /// Returns resources consumed before the inspection became inconclusive.
44    #[must_use]
45    #[inline(always)]
46    pub const fn usage(&self) -> RedactionUsage {
47        self.usage
48    }
49}
50
51impl fmt::Display for RedactionInspectionError {
52    /// Writes a safe diagnostic that never includes inspected input.
53    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
54        formatter.write_str("redaction inspection was inconclusive")
55    }
56}
57
58impl Error for RedactionInspectionError {}