Skip to main content

Sensitive

Derive Macro Sensitive 

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

Derives redactable::RedactableContainer (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 is traversed by default. Scalars pass through unchanged; nested structs/enums are walked using RedactableContainer (so external types must implement it).

  • #[sensitive(Default)]: For scalar types (i32, bool, char, etc.), redacts to default values (0, false, ‘*’). For string-like types, applies full redaction to "[REDACTED]".

  • #[sensitive(Policy)]: Applies the policy’s redaction rules to string-like values. Works for String, Option<String>, Vec<String>, Box<String>. Scalars can only use #[sensitive(Default)].

  • #[not_sensitive]: Explicit passthrough - the field is not transformed at all. Use this for foreign types that don’t implement RedactableContainer. This is equivalent to wrapping the field type in NotSensitiveValue<T>, but without changing the type signature.

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 redactable::slog::SlogRedactedExt. 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 REDACTABLE_SLOG_CRATE env var for an alternate path (e.g., my_log::slog). If neither is available, compilation fails with a clear error.