Skip to main content

qubit_redact/
lib.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//! # Qubit Redact
9//!
10//! Borrowed domain redaction for logs, errors, and structured diagnostics.
11//! Choose [`Redactor::redact_view`] for lazy formatting/serialization, or
12//! [`Redactor::redact_text`] for finalized text and a completeness summary.
13//! With `json`, `Redactor::to_json` serializes a domain view directly.
14//!
15//! ```
16//! use qubit_redact::Redactor;
17//!
18//! let output = Redactor::standard().redact_field("password", "raw-secret");
19//! assert_eq!(output.text().as_str(), "<redacted>");
20//! ```
21//!
22//! ## Domain and serialization capabilities
23//!
24//! `#[derive(Redact)]` implements [`Redact`]. `#[redact(debug)]` and
25//! `#[redact(display)]` opt into ordinary diagnostic formatting. With `serde`,
26//! the derive also generates structured redaction for views. Adding
27//! `#[redact(serde)]` makes the source's ordinary Serialize implementation
28//! redacted as well.
29//!
30//! [`RedactScalar`] supports one-field scalar newtypes without implementing
31//! business Debug, Display, or Serialize. Explicit `level` annotations at the
32//! use site determine sensitivity. Third-party values can select
33//! `#[redact(level = "secret", display)]`.
34//!
35//! ## Policies and execution
36//!
37//! Views own immutable policy snapshots but borrow live source values. Every
38//! use starts a new execution and budget. [`RedactedText`] is finalized and
39//! does not run redaction again. [`DiagnosticRedactionBatch`] shares a budget
40//! across related values; [`RedactedTextComposer`] builds one ordered message.
41//!
42//! Unmarked fields remain ordinary output. Explicit derive levels are final;
43//! runtime field rules, floors, and strict mode do not override them. Disabled
44//! policy deliberately restores source values. Generated ordinary formatting
45//! and serialization read the application default at each call; explicit
46//! views and redactors retain their captured policies.
47//!
48//! Text completion describes diagnostic completeness under the selected
49//! policy. Ordinary logging can use `output.text()` directly; audit callers
50//! can inspect summaries or reject incomplete text. This library does not
51//! erase source memory or protect output that bypasses its entry points.
52//!
53//! See the [user guide](https://github.com/qubit-ltd/rs-redact/blob/main/doc/user_guide.md)
54//! for complete setup, type/attribute tables, format integrations, and budgets.
55
56extern crate self as qubit_redact;
57
58#[cfg(feature = "derive")]
59pub use qubit_redact_derive::Redact;
60
61#[doc(hidden)]
62pub mod domain;
63mod facade;
64pub mod formats;
65mod json_feature_gate;
66mod output;
67mod policy;
68pub(crate) mod runtime;
69mod serde_feature_gate;
70#[cfg(test)]
71mod tests;
72
73pub use domain::Redact;
74pub use domain::RedactScalar;
75#[cfg(any(feature = "serde", feature = "json"))]
76pub use domain::RedactSerialize;
77pub use domain::RedactionWriter;
78pub use facade::DebugDisplay;
79pub use facade::DiagnosticRedactionBatch;
80pub use facade::DiagnosticRedactionHandle;
81pub use facade::DiagnosticRedactionOutput;
82pub use facade::RedactedText;
83pub use facade::RedactedTextComposer;
84pub use facade::RedactedView;
85pub use facade::RedactionInspection;
86pub use facade::RedactionInspectionError;
87pub use facade::RedactionReason;
88pub use facade::RedactionReasons;
89pub use facade::RedactionSummary;
90pub use facade::RedactionTextOutput;
91pub use facade::RedactionUsage;
92pub use facade::Redactor;
93pub use output::RedactionCompletion;
94pub use policy::AllowRule;
95pub use policy::FieldClassification;
96pub use policy::FieldMatchKind;
97pub use policy::FieldNameMatching;
98pub use policy::FieldsBuilder;
99#[cfg(feature = "http")]
100pub use policy::HttpContextBuilderView;
101#[cfg(feature = "http")]
102pub use policy::HttpPolicyBuilderView;
103pub use policy::MaskPolicy;
104pub use policy::MaskingPolicy;
105pub use policy::MaskingPolicyBuilder;
106pub use policy::PolicyError;
107pub use policy::PolicyLocation;
108pub use policy::RedactionFloor;
109pub use policy::RedactionFloorBuilder;
110pub use policy::RedactionLimits;
111pub use policy::RedactionLimitsBuilder;
112pub use policy::RedactionPolicy;
113pub use policy::RedactionPolicyBuilder;
114pub use policy::RedactionRules;
115pub use policy::SensitiveFieldPreset;
116pub use policy::SensitiveFieldRule;
117pub use policy::Sensitivity;
118#[cfg(feature = "json")]
119pub use policy::UnkeyedJsonValuePolicy;
120pub use policy::UnknownFieldPolicy;
121#[cfg(feature = "uri")]
122pub use policy::UriPolicyBuilderView;
123#[cfg(feature = "derive")]
124pub use qubit_redact_derive::RedactScalar;
125pub(crate) use runtime::RedactionHandle;
126pub(crate) use runtime::RedactionHandleError;