Skip to main content

SecureSerialize

Derive Macro SecureSerialize 

Source
#[derive(SecureSerialize)]
{
    // Attributes available to this derive:
    #[redact]
    #[secure_serialize]
}
Expand description

Derives SecureSerialize for a struct.

Fields marked with #[redact] or #[redact(with = "...")] will be redacted when serialized.

§Field attributes

  • #[redact] — Redact with default "<redacted>"
  • #[redact(with = "***")] — Redact with custom string "***"

§Struct attributes

  • #[secure_serialize(debug)] — Generate fmt::Debug with redacted fields (declaration order).
  • #[secure_serialize(display)] — Generate fmt::Display as compact redacted JSON.
  • #[secure_serialize(debug, display)] — Both.

§Example

#[derive(SecureSerialize, Deserialize)]
#[secure_serialize(debug, display)]
struct Config {
    pub host: String,
    #[redact]
    pub api_key: String,
    #[redact(with = "***")]
    pub password: String,
}