Skip to main content

SensitiveDisplay

Derive Macro SensitiveDisplay 

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

Derives redactable::RedactableWithFormatter using a display template.

This generates a redacted string representation by borrowing the source. The text/secret route needs no Clone; IP-map formatting clones keys and the HashMap hasher. Referenced unannotated fields require declared formatting, such as a nested SensitiveDisplay type. Unreferenced fields and constant templates remain supported.

§Field Annotations

  • (none): Uses RedactableWithFormatter and the public redactable::DeclaredFormatting declaration
  • #[sensitive(Policy)]: Apply the policy’s redaction rules
  • #[not_sensitive]: Render raw via Display (use for types without RedactableWithFormatter)

The display template is taken from #[error("...")] (thiserror-style) or from doc comments (displaydoc-style). If neither is present, the derive fails.

§Policy Formatting

A custom leaf supports policy formatting by implementing redactable::PolicyFormat. Supported containers forward to their contents. A nested RefCell borrow conflict renders as <borrowed>.

Generic policy fields declare PolicyDisplay<P> for {value}, PolicyDebug<P> for {value:?}, or both when both modes are used. The same requirements apply to concrete policy fields. These policy-specific bounds permit supported scalars and typed IP addresses without requiring structural Redactable or Clone. Missing capabilities reject the declaration even when no formatting method is called.

Use SensitiveDual instead when the same type also needs structural redaction. Its declarations must satisfy both structural and template capabilities.

§Generated Impls

  • RedactableWithFormatter: always generated.
  • ToRedacted: always generated; emits the redacted display text for slog_redacted() and tracing_redacted().
  • Debug: uses the production redacted representation in every build mode.
  • slog::Value + SlogRedacted: emits the redacted display string (requires slog feature).
  • TracingRedacted: marker trait (requires tracing feature).