#[derive(Sensitive)]
{
// Attributes available to this derive:
#[sensitive]
#[not_sensitive]
#[redactable]
}
Expand description
Derives redactable::RedactableWithMapper (and related impls) for structs and enums.
Sensitive and SensitiveDisplay are standalone derives. Use SensitiveDual when a type
needs both structural and display redaction.
§Recursive Fields
Use #[redactable(recursive)] on a field whose crate-qualified, aliased, or
mutually recursive type would otherwise create a self-referential inferred
bound. Unannotated fields retain their exact complete-type bounds.
§Field Attributes
-
No annotation: The field requires declared
Redactablebehavior and is traversed with the supplied mapper. Raw leaves need a policy or an explicit public declaration. -
#[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 the right declaration for a foreign field in a struct you own;BypassRedaction<T>is only for satisfying aRedactablebound on a value you cannot annotate.
Field operations are checked against the original declaration bounds, even
when no generated method is called. For an unannotated generic field T,
declare T: Redactable; complete container bounds may be declared instead.
Policy fields require the corresponding complete-type PolicyField<P> bound.
The recursion override omits inferred recursive predicates, but still checks
the actual field operations.
Unions are rejected at compile time.
§Generated Impls
ToRedacted: always generated. It clones, redacts and serializes, producing aRedactedValuethat carries redacted JSON. This is whySensitiverequiresCloneandserde::Serializeon the type; a missing bound is reported on the generated impl.RedactableWithMapper: always generated.Redactable: always generated. Provides.redact()and allows the type insideSensitivecontainers.Debug: uses the production redacted representation in every build mode.slog::Value+SlogRedacted(requiresslogfeature): borrowed generated output is a fixed fail-closed placeholder and never clones or serializes the raw reference. Owned values can useSlogRedactedExt::slog_redacted_jsonfor redact-then-serialize structured output.TracingRedacted(requirestracingfeature): marker trait.