[][src]Struct prompts::text::TextPrompt

pub struct TextPrompt { /* fields omitted */ }

Interactive prompt that accepts text input

Examples

use prompt::{text::TextPrompt, Prompt};
let mut prompt = TextPrompt::new("What is your name?");
match prompt.run().await {
    Ok(Some(s)) => println!("You wrote: {}", s),
    Ok(None) => println!("Prompt was aborted!"),
    Err(e) => println!("Some kind of crossterm error happened: {:?}", e),
}

Methods

impl TextPrompt[src]

pub fn new<S>(message: S) -> TextPrompt where
    S: Into<String>, 
[src]

Returns a TextPrompt ready to be run

Arguments

  • message - The message to display to the user before the prompt

pub fn with_style(self, style: Style) -> TextPrompt[src]

Mask typed letters with a given style (currently only invisible or password)

Arguments

  • style - The style to use

pub fn with_validator(
    self,
    validator: fn(input: &str) -> Result<(), String>
) -> TextPrompt
[src]

Provide a custom validation closure

Arguments

  • validator - Validation closure that accepts a string, and returns Ok if valid, or a string error to show if invalid.

Trait Implementations

impl Debug for TextPrompt[src]

impl Default for TextPrompt[src]

impl Prompt<String> for TextPrompt[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.