pub struct Credential { /* private fields */ }Expand description
A single stored login credential.
Holds a human-readable name for the credential (e.g. the service it
belongs to), a username, a password, and an optional url for the
associated login page.
§Security
Credential derives Debug, which will print password in
plaintext. Avoid logging Credential values directly (e.g. via {:?})
in contexts where logs may be persisted or exposed.
§Examples
use armoire::Credential;
let credential = Credential::builder()
.name("Example Site".to_string())
.username("alice".to_string())
.password("hunter2".to_string())
.url("https://example.com".to_string())
.build()
.expect("all required fields are set");
assert_eq!(credential.name(), "Example Site");
assert_eq!(credential.url(), Some("https://example.com"));Implementations§
Source§impl Credential
impl Credential
Sourcepub fn new<N: Into<String>, U: Into<String>, P: Into<String>>(
name: N,
username: U,
password: P,
url: Option<String>,
) -> Self
pub fn new<N: Into<String>, U: Into<String>, P: Into<String>>( name: N, username: U, password: P, url: Option<String>, ) -> Self
Creates a new Credential with the given name, username,
password, and optional url.
Prefer Credential::builder when constructing credentials at call
sites where named fields read better than positional arguments.
§Examples
use armoire::Credential;
let credential = Credential::new(
"Example Site",
"alice",
"hunter2",
None,
);Sourcepub fn builder() -> CredentialBuilder
pub fn builder() -> CredentialBuilder
Creates a CredentialBuilder for constructing a Credential with
named fields.
§Examples
use armoire::Credential;
let credential = Credential::builder()
.name("Example Site".to_string())
.username("alice".to_string())
.password("hunter2".to_string())
.build()
.expect("all required fields are set");
assert_eq!(credential.name(), "Example Site");
assert_eq!(credential.url(), None);Sourcepub fn set_name<T: Into<String>>(&mut self, name: T) -> &mut Self
pub fn set_name<T: Into<String>>(&mut self, name: T) -> &mut Self
Sets the credential’s name.
Returns &mut Self to allow chaining multiple setters:
use armoire::Credential;
let mut credential = Credential::new(
"Old Name".to_string(),
"alice".to_string(),
"hunter2".to_string(),
None,
);
credential.set_name("New Name".to_string()).set_username("bob".to_string());
assert_eq!(credential.name(), "New Name");
assert_eq!(credential.username(), "bob");Sourcepub fn set_username<T: Into<String>>(&mut self, username: T) -> &mut Self
pub fn set_username<T: Into<String>>(&mut self, username: T) -> &mut Self
Sets the credential’s username.
Returns &mut Self to allow chaining multiple setters (see
Credential::set_name for an example).
Sourcepub fn password(&self) -> &str
pub fn password(&self) -> &str
Returns the credential’s password.
§Security
The returned string is the plaintext password. Callers should avoid printing, logging, or otherwise persisting the returned value outside of its intended use.
Sourcepub fn set_password<T: Into<String>>(&mut self, password: T) -> &mut Self
pub fn set_password<T: Into<String>>(&mut self, password: T) -> &mut Self
Sets the credential’s password.
Returns &mut Self to allow chaining multiple setters (see
Credential::set_name for an example).
Trait Implementations§
Source§impl Clone for Credential
impl Clone for Credential
Source§fn clone(&self) -> Credential
fn clone(&self) -> Credential
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more