pub struct Secret<T>(/* private fields */);Expand description
A value that must never be stored or logged.
use agent_effects::redaction::Secret;
#[derive(serde::Serialize)]
struct Charge {
account: String,
card_token: Secret<String>,
}
let charge = Charge { account: "acct_1".into(), card_token: Secret::new("tok_live_x".into()) };
assert_eq!(
serde_json::to_string(&charge).unwrap(),
r#"{"account":"acct_1","card_token":"[REDACTED]"}"#
);
assert_eq!(format!("{:?}", charge.card_token), "[REDACTED]");
assert_eq!(charge.card_token.expose().map(String::as_str), Some("tok_live_x"));Implementations§
Source§impl<T> Secret<T>
impl<T> Secret<T>
Sourcepub const fn expose(&self) -> Option<&T>
pub const fn expose(&self) -> Option<&T>
The value, or None if this Secret was read back from storage,
where only "[REDACTED]" was kept.
Sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
The value, consuming the wrapper; None as for Self::expose.
Sourcepub const fn is_redacted(&self) -> bool
pub const fn is_redacted(&self) -> bool
Whether the value is gone because it was read back from storage.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Secret<T>
Reading a Secret back always yields a redacted one: the value was never
stored.
impl<'de, T> Deserialize<'de> for Secret<T>
Reading a Secret back always yields a redacted one: the value was never
stored.
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<T: Eq> Eq for Secret<T>
impl<T: PartialEq> StructuralPartialEq for Secret<T>
Auto Trait Implementations§
impl<T> Freeze for Secret<T>
impl<T> RefUnwindSafe for Secret<T>where
Option<T>: RefUnwindSafe,
impl<T> Send for Secret<T>
impl<T> Sync for Secret<T>
impl<T> Unpin for Secret<T>
impl<T> UnsafeUnpin for Secret<T>where
Option<T>: UnsafeUnpin,
impl<T> UnwindSafe for Secret<T>where
Option<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more