Struct demand::Input

source ·
pub struct Input {
    pub title: String,
    pub description: String,
    pub prompt: String,
    pub placeholder: String,
    pub inline: bool,
    pub password: bool,
    pub input: String,
    pub theme: Theme,
    /* 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

§inline: bool

Show the input inline

§password: bool

Whether to mask the input

§input: String

Input entered by the user

§theme: Theme

Colors/style of the input

Implementations§

source§

impl Input

source

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

Creates a new input with the given title.

Examples found in repository?
examples/input-password.rs (line 4)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("Set a password")
        .placeholder("Enter password")
        .prompt("Password: ")
        .password(true);
    let i = t.run().expect("error running input");
    println!("Password: {}", i);
}
More examples
Hide additional examples
examples/input.rs (line 4)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("What's your name?")
        .description("We'll use this to personalize your experience.")
        .placeholder("Enter your name")
        .prompt("Name: ");
    let i = t.run().expect("error running input");
    println!("Input: {}", i);
}
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.

Examples found in repository?
examples/input.rs (line 5)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("What's your name?")
        .description("We'll use this to personalize your experience.")
        .placeholder("Enter your name")
        .prompt("Name: ");
    let i = t.run().expect("error running input");
    println!("Input: {}", i);
}
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

Examples found in repository?
examples/input-password.rs (line 7)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("Set a password")
        .placeholder("Enter password")
        .prompt("Password: ")
        .password(true);
    let i = t.run().expect("error running input");
    println!("Password: {}", i);
}
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

Examples found in repository?
examples/input-password.rs (line 5)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("Set a password")
        .placeholder("Enter password")
        .prompt("Password: ")
        .password(true);
    let i = t.run().expect("error running input");
    println!("Password: {}", i);
}
More examples
Hide additional examples
examples/input.rs (line 6)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("What's your name?")
        .description("We'll use this to personalize your experience.")
        .placeholder("Enter your name")
        .prompt("Name: ");
    let i = t.run().expect("error running input");
    println!("Input: {}", i);
}
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.

Examples found in repository?
examples/input-password.rs (line 6)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("Set a password")
        .placeholder("Enter password")
        .prompt("Password: ")
        .password(true);
    let i = t.run().expect("error running input");
    println!("Password: {}", i);
}
More examples
Hide additional examples
examples/input.rs (line 7)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("What's your name?")
        .description("We'll use this to personalize your experience.")
        .placeholder("Enter your name")
        .prompt("Name: ");
    let i = t.run().expect("error running input");
    println!("Input: {}", i);
}
source

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

Sets the theme of the input

source

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

Displays the input to the user and returns the response

Examples found in repository?
examples/input-password.rs (line 8)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("Set a password")
        .placeholder("Enter password")
        .prompt("Password: ")
        .password(true);
    let i = t.run().expect("error running input");
    println!("Password: {}", i);
}
More examples
Hide additional examples
examples/input.rs (line 8)
3
4
5
6
7
8
9
10
fn main() {
    let t = Input::new("What's your name?")
        .description("We'll use this to personalize your experience.")
        .placeholder("Enter your name")
        .prompt("Name: ");
    let i = t.run().expect("error running input");
    println!("Input: {}", i);
}

Auto Trait Implementations§

§

impl RefUnwindSafe for Input

§

impl Send for Input

§

impl Sync for Input

§

impl Unpin for Input

§

impl UnwindSafe for Input

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.