Skip to main content

Sensitive

Struct Sensitive 

Source
pub struct Sensitive<T> { /* private fields */ }
Expand description

Wraps a secret so Debug and Display always render "[REDACTED]" while the value stays usable through Sensitive::expose.

Deliberately attribute-free: no derive macros, so nothing can accidentally drift into leaking. The redacting impls carry no T: Debug/T: Display bound, which means a container’s derived Debug also renders "[REDACTED]" for the field — the value cannot escape through any formatting path.

Deserialization is always supported (loading configuration is the point). Serialization is opt-in behind the serde feature, because serializing secrets invites accidental disclosure — enable it only when your pipeline genuinely needs to write the value back out. Every intentional read goes through expose, which makes secret usage grep-friendly: grep -rn '\.expose()' audits every touchpoint.

§Example

use config_kit::Sensitive;

let token = Sensitive::new("hunter2".to_owned());
assert_eq!(format!("{token:?}"), "[REDACTED]");
assert_eq!(format!("{token}"), "[REDACTED]");
assert_eq!(token.expose(), "hunter2");

Implementations§

Source§

impl<T> Sensitive<T>

Source

pub fn new(value: T) -> Self

Wraps value for redacted transport.

Source

pub fn expose(&self) -> &T

Explicit, grep-friendly access to the wrapped secret.

Source

pub fn into_inner(self) -> T

Consumes the wrapper, returning the secret. Like expose, this is an explicit declassification point.

Trait Implementations§

Source§

impl<T> Debug for Sensitive<T>

Source§

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

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

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

Source§

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

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

impl<T> Display for Sensitive<T>

Source§

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

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

impl<T> From<T> for Sensitive<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

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> UnsafeUnpin for Sensitive<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Sensitive<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.