Skip to main content

Sensitive

Derive Macro Sensitive 

Source
#[derive(Sensitive)]
{
    // Attributes available to this derive:
    #[sensitive]
}
Expand description

Derives redaction::SensitiveType (and related impls) for structs and enums.

§Container Attributes

These attributes are placed on the struct/enum itself:

  • #[sensitive(skip_debug)] - Opt out of Debug impl generation. Use this when you need a custom Debug implementation or the type already derives Debug elsewhere.

§Field Attributes

  • No annotation: The field passes through unchanged. Use this for fields that don’t contain sensitive data, including external types like chrono::DateTime or rust_decimal::Decimal.

  • #[sensitive]: For scalar types (i32, bool, char, etc.), redacts to default values (0, false, ‘X’). For struct/enum types that derive Sensitive, walks into them using SensitiveType.

  • #[sensitive(Classification)]: Treats the field as a sensitive string-like value and applies the classification’s policy. Works for String, Option<String>, Vec<String>, Box<String>. The type must implement SensitiveValue.

  • #[sensitive] on Box<dyn Trait>: The derive detects the specific syntax Box<dyn Trait> and calls redaction::redact_boxed. This only matches the unqualified form (not std::boxed::Box<dyn Trait> or aliases). The trait object must implement RedactableBoxed.

Unions are rejected at compile time.

§Additional Generated Impls

  • Debug: when not building with cfg(any(test, feature = "testing")), sensitive fields are formatted as the string "[REDACTED]" rather than their values. Use #[sensitive(skip_debug)] on the container to opt out.
  • slog::Value (behind cfg(feature = "slog")): implemented by cloning the value and routing it through redaction::slog::IntoRedactedJson. Note: this impl requires Clone and serde::Serialize because it emits structured JSON. The derive first looks for a top-level slog crate; if not found, it checks the REDACTION_SLOG_CRATE env var for an alternate path (e.g., my_log::slog). If neither is available, compilation fails with a clear error.