3 unstable releases
0.1.0 | Jun 22, 2024 |
---|---|
0.0.0-alpha.1 | Jun 22, 2024 |
#437 in Procedural macros
9KB
99 lines
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 maskedDisplay
trait implementation. - Derive
DebugMasked
for maskedDebug
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.
Dependencies
~250–700KB
~17K SLoC