Skip to main content

Secret

Struct Secret 

Source
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>

Source

pub fn new(urn_str: &str) -> Result<Self, UrnParseError>

Creates an unbound secret from a URN string.

Source

pub fn urn(&self) -> &Urn

Returns the URN that identifies this secret.

The URN is available regardless of whether the secret has been bound. It contains only the source identifier and secret name — never the secret value — so it is safe to log, store, or compare.

The primary use case is constructing a second unbound secret with the same identity, for example to hand the same logical secret to two independent subsystems that each bind it separately:

let original: Secret<String> =
    Secret::new("urn:secrets-rs:env:API_KEY").unwrap();

// Create a second unbound secret with the same URN.
let copy: Secret<String> =
    Secret::new(&original.urn().to_string()).unwrap();
Source

pub fn value(&self) -> Result<&T, UnboundError>

Returns the secret value, or an UnboundError if not yet bound.

Source

pub fn masked_value(&self) -> String

Returns the masked value string — safe to log or serialize by default.

Source

pub fn bind(&mut self, registry: &SourceRegistry) -> Result<(), BindError>

Fetches the secret from the appropriate source in registry and stores it. Returns BindError if the source is not registered or the lookup fails.

Trait Implementations§

Source§

impl<T: SecretValue> Debug for Secret<T>

Always displays the masked value — the real value is never revealed via Debug.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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.

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: SecretValue> Display for Secret<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: SecretValue> Serialize for Secret<T>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Secret<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Secret<T>
where T: RefUnwindSafe,

§

impl<T> Send for Secret<T>
where T: Send,

§

impl<T> Sync for Secret<T>
where T: Sync,

§

impl<T> Unpin for Secret<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Secret<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Secret<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,