Skip to main content

Crate sensitive_fmt

Crate sensitive_fmt 

Source
Expand description

Derive Debug and Display for Rust structs while honoring sensitive field attributes. Designed for keeping PHI, PII, secrets, and tokens out of log lines.

§Example

use sensitive_fmt::{SensitiveDebug, SensitiveDisplay};

#[derive(SensitiveDebug, SensitiveDisplay)]
struct Patient {
    id: u64,
    #[sensitive(truncate = 4)] mrn: String,
    #[sensitive(redact)]       email: String,
}

let p = Patient {
    id: 42,
    mrn: "MRN-12345-WXYZ".into(),
    email: "alice@example.com".into(),
};
assert_eq!(
    format!("{p}"),
    "Patient { id: 42, mrn: ****WXYZ, email: REDACTED }",
);

See the README for the full attribute reference.

Derive Macros§

SensitiveDebug
SensitiveDisplay