macro_rules! secure_sanitize_struct {
(
$(#[$attr:meta])*
$vis:vis struct $name:ident {
$(
$(#[$field_attr:meta])*
$field_vis:vis $field:ident: $field_ty:ty
),* $(,)?
}
) => { ... };
}Expand description
Declare a struct and generate SecureSanitize for all fields.
This is a dependency-free alternative to a derive macro. Each field type
must implement SecureSanitize. The macro does not implement Drop, so
use this form when the type needs custom drop behavior or is wrapped in
Secret.
This macro intentionally supports named-field structs without generics or
where clauses. For generic structs, implement SecureSanitize manually
so the impl generics and bounds stay explicit.
use sanitization::{secure_sanitize_struct, SecretBytes, SecureSanitize};
secure_sanitize_struct! {
struct Credentials {
key: SecretBytes<32>,
nonce: SecretBytes<12>,
}
}
let mut credentials = Credentials {
key: SecretBytes::from_array([1; 32]),
nonce: SecretBytes::from_array([2; 12]),
};
credentials.secure_sanitize();