Skip to content

derive(Display, Debug) should allow opt-outs of fields #146750

@Firstyear

Description

@Firstyear

Lets say we have a struct like

#[derive(Debug, Display)]
struct PasswordResetRequest {
    username: String,
    password: String,
}

If this were logged or printed then we would be disclosing the user's password into logs or other output mediums.

Today one can avoid this by manually implementing Debug and Display on structs that may have sensitive data, but it would be simpler if we could opt-out of fields being displayed. For example

#[derive(Debug, Display)]
struct PasswordResetRequest {
    username: String,
    #[display(sensitive)]
    password: String,
}

This would allow the password field to be skipped (or at least redacted) in outputs.

alternatives

A secretstring library that wraps all strings that should be redacted. To date I'm not aware of one, but I can see that this has value in std as a whole.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions