Struct dialoguer::Password

source ·
pub struct Password<'a> { /* private fields */ }
Expand description

Renders a password input prompt.

§Example

use dialoguer::Password;

fn main() {
    let password = Password::new()
        .with_prompt("New Password")
        .with_confirmation("Confirm password", "Passwords mismatching")
        .interact()
        .unwrap();

    println!("Your password length is: {}", password.len());
}

Implementations§

source§

impl Password<'static>

source

pub fn new() -> Password<'static>

Creates a password input prompt with default theme.

source§

impl Password<'_>

source

pub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self

Sets the password input prompt.

source

pub fn report(self, val: bool) -> Self

Indicates whether to report confirmation after interaction.

The default is to report.

source

pub fn with_confirmation<A, B>(self, prompt: A, mismatch_err: B) -> Self
where A: Into<String>, B: Into<String>,

Enables confirmation prompting.

source

pub fn allow_empty_password(self, allow_empty_password: bool) -> Self

Allows/Disables empty password.

By default this setting is set to false (i.e. password is not empty).

source

pub fn interact(self) -> Result<String>

Enables user interaction and returns the result.

If the user confirms the result is Ok(), Err() otherwise. The dialog is rendered on stderr.

source

pub fn interact_on(self, term: &Term) -> Result<String>

Like interact but allows a specific terminal to be set.

source§

impl<'a> Password<'a>

source

pub fn validate_with<V>(self, validator: V) -> Self
where V: PasswordValidator + 'a, V::Err: ToString,

Registers a validator.

§Example
use dialoguer::Password;

fn main() {
    let password: String = Password::new()
        .with_prompt("Enter password")
        .validate_with(|input: &String| -> Result<(), &str> {
            if input.chars().count() > 8 {
                Ok(())
            } else {
                Err("Password must be longer than 8")
            }
        })
        .interact()
        .unwrap();
}
source

pub fn with_theme(theme: &'a dyn Theme) -> Self

Creates a password input prompt with a specific theme.

§Example
use dialoguer::{theme::ColorfulTheme, Password};

fn main() {
    let password = Password::with_theme(&ColorfulTheme::default())
        .interact()
        .unwrap();
}

Trait Implementations§

source§

impl<'a> Clone for Password<'a>

source§

fn clone(&self) -> Password<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Password<'static>

source§

fn default() -> Password<'static>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Password<'a>

§

impl<'a> !RefUnwindSafe for Password<'a>

§

impl<'a> !Send for Password<'a>

§

impl<'a> !Sync for Password<'a>

§

impl<'a> Unpin for Password<'a>

§

impl<'a> !UnwindSafe for Password<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.