derive-masked

Crates.ioderive-masked
lib.rsderive-masked
version0.1.0
sourcesrc
created_at2024-06-22 03:35:26.616053
updated_at2024-06-22 07:15:16.110715
descriptionAdds #[derive(x)] macros for implementing the Debug and Display traits masking out sensitive fields
homepagehttps://github.com/okcodes/derive-masked
repositoryhttps://github.com/okcodes/derive-masked
max_upload_size
id1280149
size27,083
(okcodes)

documentation

https://docs.rs/derive-masked

README

derive-masked

derive-masked is a procedural macro crate for deriving Display and Debug implementations that mask sensitive fields, ensuring secure and controlled output of struct data.

Features

  • Derive DisplayMasked for masked Display trait implementation.
  • Derive DebugMasked for masked Debug trait implementation.
  • Mask sensitive fields with the #[masked] attribute.

You can derive both DisplayMasked and DebugMasked if you want.

Usage

Add to Cargo.toml:

cargo add derive-masked

Example

use derive_masked::{DebugMasked, DisplayMasked};

#[derive(DebugMasked, DisplayMasked)]
struct User {
    name: String,
    #[masked]
    password: String,
}

fn main() {
    let user = User {
        name: "Alice".to_string(),
        password: "super_secret".to_string(),
    };

    // Uses DisplayMasked. Output: User { name: Alice, password: ***** }
    println!("{}", user);

    // Uses DebugMasked. Output: User { name: "Alice", password: ***** }
    println!("{:?}", user);

    // Uses DebugMasked with pretty print formatter. Output:
    // User {
    //     name: "Alice",
    //     password: *****
    // }
    println!("{:#?}", user);
}

For more examples, see the examples directory.

Getting Help

For support, file an issue on GitHub.

License

Licensed under either MIT or Apache 2.0, at your option.

Commit count: 26

cargo fmt