pub struct SecretString(/* private fields */);Expand description
A string wrapper that masks its value when printed via Debug or
Display, to prevent secrets (API keys, tokens,
passwords, …) from
accidentally ending up in logs or error messages.
The real value is still accessible via SecretString::expose_secret,
and is preserved (not masked) when (de)serialized with serde, since
serialization is generally used to persist or transmit the value rather
than to display it.
This is the Rust analogue of upstream’s SecretString(str), which masks
its repr() but not its str()/__format__ behavior. Rust has no
implicit string-like coercions, so the equivalent masked-only surface is
Debug and Display; call SecretString::expose_secret whenever the
real value is needed (e.g. to authenticate a request).
Implementations§
Source§impl SecretString
impl SecretString
Sourcepub fn new(value: impl Into<String>) -> SecretString
pub fn new(value: impl Into<String>) -> SecretString
Wrap value as a SecretString.
Sourcepub fn expose_secret(&self) -> &str
pub fn expose_secret(&self) -> &str
Return the real, unmasked value.
Named to match upstream’s get_secret_value() / the common Rust
secrecy-crate convention, and to make call sites grep-able for
audits of where secrets are actually exposed.
Trait Implementations§
Source§impl Clone for SecretString
impl Clone for SecretString
Source§fn clone(&self) -> SecretString
fn clone(&self) -> SecretString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more