#[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 bothSensitiveandSensitiveDisplayon the same type.Sensitiveskips itsDebugimpl (lettingSensitiveDisplayprovide it), andSensitiveDisplayskips itsslog/tracingimpls (lettingSensitiveprovide them). For non-generic types, generated code checks that the counterpart derive is present. Genericdualtypes 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 forString,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 implementRedactableWithMapper. This is equivalent to wrapping the field type inNotSensitiveValue<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’scfg(test)builds or whenredactable’stestingfeature is enabled. Skipped when#[sensitive(dual)]is set.slog::Value+SlogRedacted(requiresslogfeature): implemented by cloning the value and routing it throughredactable::slog::SlogRedactedExt. RequiresCloneandserde::Serializebecause it emits structured JSON. Generated dependency paths resolve throughredactable::__private, including when the dependency is renamed.TracingRedacted(requirestracingfeature): marker trait.