pub struct Sensitive<T: Default + Zeroize>(pub T);Expand description
A wrapper type for sensitive data that obscures the value in debug output and securely zeros memory when dropped.
This type is useful for wrapping secrets, passwords, API keys, and other sensitive information that should not be accidentally exposed in logs, error messages, or debug output.
The inner value remains accessible through the public field 0, but when
formatted using Debug, it displays as Sensitive(****) instead of the
actual value.
§Type Parameters
T: The type of the sensitive value, which must implementDefault
§Examples
use axum_conf::Sensitive;
let api_key = Sensitive::from("secret-key-12345");
println!("{:?}", api_key); // Prints: Sensitive(****)
// Access the actual value when needed
let key_value: &str = &api_key.0;§Security Features
- Debug hiding: Debug output shows
Sensitive(****)instead of the value - Memory zeroing: When
Sensitive<String>is dropped, the memory is securely overwritten with zeros to prevent secrets from lingering in memory
§Security Limitations
This type does NOT:
- Prevent the value from being read if you have access to the
Sensitiveinstance - Encrypt or secure the value in memory while in use
- Prevent the value from being serialized if using
Serialize - Prevent the compiler from copying the value (use with care in generic contexts)
For true security, combine with other security measures like secure memory handling.
§Derive Macros
Uses ZeroizeOnDrop from the zeroize crate to automatically zero memory when dropped.
Tuple Fields§
§0: TImplementations§
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Sensitive<T>
impl<'de, T> Deserialize<'de> for Sensitive<T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<T> Freeze for Sensitive<T>where
T: Freeze,
impl<T> RefUnwindSafe for Sensitive<T>where
T: RefUnwindSafe,
impl<T> Send for Sensitive<T>where
T: Send,
impl<T> Sync for Sensitive<T>where
T: Sync,
impl<T> Unpin for Sensitive<T>where
T: Unpin,
impl<T> UnwindSafe for Sensitive<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more