pub struct Secret<T: SecretValue> { /* private fields */ }Expand description
A secret value identified by a URN.
Before bind is called the secret is unbound; accessing
its value returns an UnboundError. All default display paths (
Display, Debug, serde serialization) emit the masked
value, which is safe to include in logs.
§Masked value format
- Unbound:
urn:secrets-rs:env:KEY [UNBOUND] - Bound:
urn:secrets-rs:env:KEY [string:12]
Implementations§
Source§impl<T: SecretValue> Secret<T>
impl<T: SecretValue> Secret<T>
Sourcepub fn new(urn_str: &str) -> Result<Self, UrnParseError>
pub fn new(urn_str: &str) -> Result<Self, UrnParseError>
Creates an unbound secret from a URN string.
Sourcepub fn value(&self) -> Result<&T, UnboundError>
pub fn value(&self) -> Result<&T, UnboundError>
Returns the secret value, or an UnboundError if not yet bound.
Sourcepub fn masked_value(&self) -> String
pub fn masked_value(&self) -> String
Returns the masked value string — safe to log or serialize by default.
Trait Implementations§
Source§impl<T: SecretValue> Debug for Secret<T>
Always displays the masked value — the real value is never revealed via Debug.
impl<T: SecretValue> Debug for Secret<T>
Always displays the masked value — the real value is never revealed via Debug.
Source§impl<'de, T: SecretValue> Deserialize<'de> for Secret<T>
Deserializes a Secret<T> from a URN string, producing an unbound secret.
impl<'de, T: SecretValue> Deserialize<'de> for Secret<T>
Deserializes a Secret<T> from a URN string, producing an unbound secret.
The input must be a valid urn:secrets-rs:<source_id>:<name> string.
Any other value is rejected with a descriptive error. The resulting secret
must be bound via bind_all before its value can be accessed.