Skip to main content

Sensitive

Derive Macro Sensitive 

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

Derives redactable::RedactableWithMapper (and related impls) for structs and enums.

§Container Attributes

These attributes are placed on the struct/enum itself:

  • #[sensitive(dual)] - Use when deriving both Sensitive and SensitiveDisplay on the same type. Sensitive skips its Debug impl (letting SensitiveDisplay provide it), and SensitiveDisplay skips its slog/tracing impls (letting Sensitive provide them).

§Field Attributes

  • No annotation: The field is traversed by default. Scalars pass through unchanged; nested structs/enums are walked using RedactableWithMapper (so external types must implement it).

  • #[sensitive(Secret)]: 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(Secret)].

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

Unions are rejected at compile time.

§Generated Impls

  • RedactableWithMapper: always generated.
  • Debug: redacted in production, actual values in test/testing builds. Skipped when #[sensitive(dual)] is set.
  • slog::Value + SlogRedacted (requires slog feature): implemented by cloning the value and routing it through redactable::slog::SlogRedactedExt. 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.
  • TracingRedacted (requires tracing feature): marker trait.