[][src]Struct spirit::utils::Hidden

#[repr(transparent)]
pub struct Hidden<T>(pub T);

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)?);

Trait Implementations

impl<T: PartialEq> PartialEq<Hidden<T>> for Hidden<T>[src]

impl<T: Default> Default for Hidden<T>[src]

impl<T: Ord> Ord for Hidden<T>[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<T: Clone> Clone for Hidden<T>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T> From<T> for Hidden<T>[src]

impl<T: Eq> Eq for Hidden<T>[src]

impl<T: PartialOrd> PartialOrd<Hidden<T>> for Hidden<T>[src]

impl<T> DerefMut for Hidden<T>[src]

impl<T> Deref for Hidden<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: Hash> Hash for Hidden<T>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T> Debug for Hidden<T>[src]

impl<T> Serialize for Hidden<T>[src]

impl<'de, T> Deserialize<'de> for Hidden<T> where
    T: Deserialize<'de>, 
[src]

impl<T> StructDoc for Hidden<T> where
    T: StructDoc
[src]

Auto Trait Implementations

impl<T> Send for Hidden<T> where
    T: Send

impl<T> Sync for Hidden<T> where
    T: Sync

Blanket Implementations

impl<T> IntoResult for T[src]

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

impl<T> Erased for T