qubit_redact/install_global_policy_error.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//! Error returned when a process-wide policy is installed twice.
9
10use std::{
11 error::Error,
12 fmt,
13};
14
15use crate::RedactionPolicy;
16
17/// Owns the policy that could not be installed because a global policy was
18/// already installed.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct InstallGlobalPolicyError(pub(crate) RedactionPolicy);
21
22impl InstallGlobalPolicyError {
23 /// Returns the policy that was rejected by the global slot.
24 #[must_use = "use the rejected policy or drop it explicitly"]
25 pub fn into_policy(self) -> RedactionPolicy {
26 self.0
27 }
28}
29
30impl fmt::Display for InstallGlobalPolicyError {
31 /// Writes the stable installation error message.
32 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
33 formatter.write_str("the global redaction policy is already installed")
34 }
35}
36
37impl Error for InstallGlobalPolicyError {}