| Crates.io | derive-masked |
| lib.rs | derive-masked |
| version | 0.1.0 |
| created_at | 2024-06-22 03:35:26.616053+00 |
| updated_at | 2024-06-22 07:15:16.110715+00 |
| description | Adds #[derive(x)] macros for implementing the Debug and Display traits masking out sensitive fields |
| homepage | https://github.com/okcodes/derive-masked |
| repository | https://github.com/okcodes/derive-masked |
| max_upload_size | |
| id | 1280149 |
| size | 27,083 |
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.
DisplayMasked for masked Display trait implementation.DebugMasked for masked Debug trait implementation.#[masked] attribute.You can derive both DisplayMasked and DebugMasked if you want.
Add to Cargo.toml:
cargo add derive-masked
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.
For support, file an issue on GitHub.
Licensed under either MIT or Apache 2.0, at your option.