Struct demand::Input

source ·
pub struct Input<'a> {
    pub title: String,
    pub description: String,
    pub prompt: String,
    pub placeholder: String,
    pub suggestions: Vec<&'a str>,
    pub inline: bool,
    pub password: bool,
    pub input: String,
    pub theme: &'a Theme,
    pub validation: fn(_: &str) -> Result<(), &str>,
    /* private fields */
}
Expand description

Single line text input

§Example

use demand::Input;

let input = Input::new("What's your name?")
  .description("We'll use this to personalize your experience.")
  .placeholder("Enter your name");
let name = input.run().expect("error running input");

Fields§

§title: String

The title of the input

§description: String

A description to display after the title

§prompt: String

A prompt to display after the description

§placeholder: String

A placeholder to display in the input

§suggestions: Vec<&'a str>

A list of suggestions to autocomplete from

§inline: bool

Show the input inline

§password: bool

Whether to mask the input

§input: String

Input entered by the user

§theme: &'a Theme

Colors/style of the input

§validation: fn(_: &str) -> Result<(), &str>

Validation function

Implementations§

source§

impl<'a> Input<'a>

source

pub fn new<S: Into<String>>(title: S) -> Self

Creates a new input with the given title.

source

pub fn description(self, description: &str) -> Self

Sets the description of the input.

If the input is inline, it is displayed to the right of the title. Otherwise, it is displayed below the title.

source

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

Sets the inline flag of the input.

If true, the input is displayed inline with the title

source

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

Sets the password flag of the input.

If true, the input is masked with asterisks

source

pub fn placeholder(self, placeholder: &str) -> Self

Sets the placeholder of the input.

The placeholder is displayed in the input before the user enters any text

source

pub fn suggestions(self, suggestions: Vec<&'static str>) -> Self

Sets the suggestions of the input

source

pub fn prompt(self, prompt: &str) -> Self

Sets the prompt of the input.

The prompt is displayed after the title and description. If empty, the default prompt > is displayed.

source

pub fn theme(self, theme: &'a Theme) -> Self

Sets the theme of the input

source

pub fn validation(self, validation: fn(_: &str) -> Result<(), &str>) -> Self

Sets the validation for the input.

If the input is valid, the Result is Ok(()). Otherwise, the Result is Err(&str).

source

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

Displays the input to the user and returns the response

Auto Trait Implementations§

§

impl<'a> Freeze for Input<'a>

§

impl<'a> RefUnwindSafe for Input<'a>

§

impl<'a> Send for Input<'a>

§

impl<'a> Sync for Input<'a>

§

impl<'a> Unpin for Input<'a>

§

impl<'a> UnwindSafe for Input<'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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.