pub struct SecretString<T>(/* private fields */)
where
T: AsRef<str>;Expand description
A string wrapper that hides its contents when printed or formatted for debugging.
It WILL however serialize the value when using serde serialization/deserialization.
§Examples
use secret_string::SecretString;
let secret = SecretString::new("my_secret_password");
assert_eq!(format!("{}", secret), "******************");
assert_eq!(format!("{:?}", secret), "SecretString(******************)");
assert_eq!(secret.value(), "my_secret_password");Implementations§
Source§impl<T: AsRef<str>> SecretString<T>
impl<T: AsRef<str>> SecretString<T>
pub fn new(s: T) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn as_stars(&self) -> String
pub fn as_stars(&self) -> String
Returns a string of asterisks (*) with the same length as the secret string.
Sourcepub fn as_stars_with_with_len(&self, len: usize) -> String
pub fn as_stars_with_with_len(&self, len: usize) -> String
In case you don’t want to show the length of the secret
Trait Implementations§
Source§impl<T> Clone for SecretString<T>
impl<T> Clone for SecretString<T>
Source§fn clone(&self) -> SecretString<T>
fn clone(&self) -> SecretString<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Hash for SecretString<T>
impl<T> Hash for SecretString<T>
Source§impl<T> Ord for SecretString<T>
impl<T> Ord for SecretString<T>
Source§fn cmp(&self, other: &SecretString<T>) -> Ordering
fn cmp(&self, other: &SecretString<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T> PartialEq for SecretString<T>
impl<T> PartialEq for SecretString<T>
Source§impl<T> PartialOrd for SecretString<T>
impl<T> PartialOrd for SecretString<T>
impl<T> Eq for SecretString<T>
impl<T> StructuralPartialEq for SecretString<T>
Auto Trait Implementations§
impl<T> Freeze for SecretString<T>where
T: Freeze,
impl<T> RefUnwindSafe for SecretString<T>where
T: RefUnwindSafe,
impl<T> Send for SecretString<T>where
T: Send,
impl<T> Sync for SecretString<T>where
T: Sync,
impl<T> Unpin for SecretString<T>where
T: Unpin,
impl<T> UnwindSafe for SecretString<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