#[repr(transparent)]pub struct Hidden<T>(pub T);Expand description
A wrapper to hide a configuration field from logs.
This acts in as much transparent way as possible towards the field inside. It only replaces the
Debug and Serialize implementations with returning "******".
The idea is if the configuration contains passwords, they shouldn’t leak into the logs. Therefore, wrap them in this, eg:
use std::io::Write;
use std::str;
use spirit::utils::Hidden;
#[derive(Debug)]
struct Cfg {
username: String,
password: Hidden<String>,
}
let cfg = Cfg {
username: "me".to_owned(),
password: "secret".to_owned().into(),
};
let mut buffer: Vec<u8> = Vec::new();
write!(&mut buffer, "{:?}", cfg)?;
assert_eq!(r#"Cfg { username: "me", password: "******" }"#, str::from_utf8(&buffer)?);Tuple Fields§
§0: TTrait Implementations§
Source§impl<'de, T> Deserialize<'de> for Hidden<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Hidden<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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: Ord> Ord for Hidden<T>
impl<T: Ord> Ord for Hidden<T>
Source§impl<T: PartialOrd> PartialOrd for Hidden<T>
impl<T: PartialOrd> PartialOrd for Hidden<T>
Source§impl<T> StructDoc for Hidden<T>where
T: StructDoc,
impl<T> StructDoc for Hidden<T>where
T: StructDoc,
Source§fn document() -> Documentation
fn document() -> Documentation
Returns the documentation for the type. Read more
impl<T: Eq> Eq for Hidden<T>
impl<T> StructuralPartialEq for Hidden<T>
Auto Trait Implementations§
impl<T> Freeze for Hidden<T>where
T: Freeze,
impl<T> RefUnwindSafe for Hidden<T>where
T: RefUnwindSafe,
impl<T> Send for Hidden<T>where
T: Send,
impl<T> Sync for Hidden<T>where
T: Sync,
impl<T> Unpin for Hidden<T>where
T: Unpin,
impl<T> UnwindSafe for Hidden<T>where
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of
Access::load.