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). For non-generic types, generated code checks that the counterpart derive is present. Generic dual types cannot be checked at derive time; missing counterparts surface later as trait-bound errors when the type is used.

§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.
  • Redactable: always generated. Provides .redact() and certifies the type for the redacted-output extension traits (RedactedOutputExt, RedactedJsonExt, SlogRedactedExt).
  • Debug: redacted by default; actual values in the consumer’s cfg(test) builds or when redactable’s testing feature is enabled. 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. Generated dependency paths resolve through redactable::__private, including when the dependency is renamed.
  • TracingRedacted (requires tracing feature): marker trait.