1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! # redactkit
//!
//! Small toolkit for redacting sensitive data in debug output and tracing logs.
//!
//! > **Warning:** `redactkit` redacts formatted output only.
//! > It does not modify or erase original field values in memory.
//!
//! ## Features
//!
//! | Feature | Default | Description |
//! | --- | --- | --- |
//! | `std` | yes | Standard library support. |
//! | `derive` | yes | Enables the `RedactDebug` derive macro. |
//! | `regex` | no | Enables regex-based field and value rules. |
//! | `tracing` | no | Enables `tracing-subscriber` field redaction. |
//!
//! ## Derive example
//!
//! ```
//! # #[cfg(feature = "derive")]
//! # {
//! use redactkit::RedactDebug;
//!
//! #[derive(RedactDebug)]
//! struct User {
//! username: String,
//! #[redact]
//! password: String,
//! }
//!
//! let user = User {
//! username: "anna".to_string(),
//! password: "s3cr3t".to_string(),
//! };
//!
//! assert_eq!(
//! format!("{user:?}"),
//! "User { username: \"anna\", password: \"******\" }"
//! );
//! # }
//! ```
//!
//! ## Builder example
//!
//! ```
//! use redactkit::Redactor;
//!
//! let redactor = Redactor::builder()
//! .field("password")
//! .field("token")
//! .mask("[hidden]")
//! .build();
//!
//! assert_eq!(redactor.redact_field("password", "secret"), "[hidden]");
//! assert_eq!(redactor.redact_field("username", "anna"), "anna");
//! ```
//!
//! ## Default redactor
//!
//! ```
//! let redactor = redactkit::default_redactor();
//!
//! assert_eq!(redactor.redact_field("password", "secret"), "******");
//! assert_eq!(redactor.redact_field("api_key", "abc123"), "******");
//! ```
//!
//! ## Regex rules
//!
//! ```
//! # #[cfg(feature = "regex")]
//! # {
//! use redactkit::Redactor;
//!
//! let redactor = Redactor::builder()
//! .field_pattern("(?i)token|secret")
//! .unwrap()
//! .value_pattern(r"\d{4}", "****")
//! .unwrap()
//! .build();
//!
//! assert_eq!(redactor.redact_field("api_token", "abcd"), "******");
//! assert_eq!(redactor.redact_field("note", "card 1234"), "card ****");
//! # }
//! ```
//!
//! ## Tracing integration
//!
//! ```
//! # #[cfg(feature = "tracing")]
//! # {
//! use tracing_subscriber::fmt;
//!
//! fmt()
//! .fmt_fields(redactkit::tracing::redact_fields())
//! .init();
//! # }
//! ```
pub use RedactorBuilder;
pub use Error;
pub use ;
pub use RedactDebug;