Secret
A value that must not leak through logs, error messages or {:?}: printing it shows
[REDACTED] instead of the content.
The only way to read it is the explicit expose (or
into_inner), which makes every use of the secret easy to find in a code
review. It is not PartialEq, Hash or serializable, so it cannot be compared, used as a key
or written out by accident. It does not wipe the memory when dropped: that needs
unsafe code, which this crate forbids, so use a dedicated crate such as zeroize when a
value must not linger in memory.
Import
Section titled “Import”Cargo feature secret (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”Wraps value.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | T | The sensitive value. |
Returns
Self — The wrapper, which hides the value from Debug and Display.
expose
Section titled “expose”Borrows the value.
Returns
&T — A reference to the wrapped value: the one place where it is read.
into_inner
Section titled “into_inner”Unwraps the value.
Returns
T — The wrapped value, no longer protected.
