Input

Struct Input 

Source
pub struct Input { /* private fields */ }

Implementations§

Source§

impl Input

Source

pub fn new(prompt: impl Into<String>) -> Self

Examples found in repository?
examples/input_basic.rs (line 6)
3fn main() {
4    println!("=== Input Component Demo ===\n");
5
6    let result = Input::new("Enter your name:").default("Alice").run();
7
8    match result {
9        Ok(name) => println!("\nHello, {}!", name),
10        Err(e) => eprintln!("\nError: {}", e),
11    }
12}
More examples
Hide additional examples
examples/combined.rs (line 7)
3fn main() {
4    println!("=== Combined Components Demo ===\n");
5
6    // 1. Input
7    let name = match Input::new("What's your name?").run() {
8        Ok(n) => n,
9        Err(e) => {
10            eprintln!("Error: {}", e);
11            return;
12        }
13    };
14
15    println!();
16
17    // 2. Select
18    let color = match Select::new("Choose your favorite color:")
19        .option("Red", "red")
20        .option("Green", "green")
21        .option("Blue", "blue")
22        .run()
23    {
24        Ok(c) => c,
25        Err(e) => {
26            eprintln!("Error: {}", e);
27            return;
28        }
29    };
30
31    println!();
32
33    // 3. Confirm
34    let confirmed = match Confirm::new("Save preferences?").default(true).run() {
35        Ok(c) => c,
36        Err(e) => {
37            eprintln!("Error: {}", e);
38            return;
39        }
40    };
41
42    println!();
43
44    if confirmed {
45        println!("✓ Saved: name={}, color={}", name, color);
46    } else {
47        println!("✗ Not saved");
48    }
49}
Source

pub fn default(self, default: impl Into<String>) -> Self

Examples found in repository?
examples/input_basic.rs (line 6)
3fn main() {
4    println!("=== Input Component Demo ===\n");
5
6    let result = Input::new("Enter your name:").default("Alice").run();
7
8    match result {
9        Ok(name) => println!("\nHello, {}!", name),
10        Err(e) => eprintln!("\nError: {}", e),
11    }
12}
Source

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

Examples found in repository?
examples/input_basic.rs (line 6)
3fn main() {
4    println!("=== Input Component Demo ===\n");
5
6    let result = Input::new("Enter your name:").default("Alice").run();
7
8    match result {
9        Ok(name) => println!("\nHello, {}!", name),
10        Err(e) => eprintln!("\nError: {}", e),
11    }
12}
More examples
Hide additional examples
examples/combined.rs (line 7)
3fn main() {
4    println!("=== Combined Components Demo ===\n");
5
6    // 1. Input
7    let name = match Input::new("What's your name?").run() {
8        Ok(n) => n,
9        Err(e) => {
10            eprintln!("Error: {}", e);
11            return;
12        }
13    };
14
15    println!();
16
17    // 2. Select
18    let color = match Select::new("Choose your favorite color:")
19        .option("Red", "red")
20        .option("Green", "green")
21        .option("Blue", "blue")
22        .run()
23    {
24        Ok(c) => c,
25        Err(e) => {
26            eprintln!("Error: {}", e);
27            return;
28        }
29    };
30
31    println!();
32
33    // 3. Confirm
34    let confirmed = match Confirm::new("Save preferences?").default(true).run() {
35        Ok(c) => c,
36        Err(e) => {
37            eprintln!("Error: {}", e);
38            return;
39        }
40    };
41
42    println!();
43
44    if confirmed {
45        println!("✓ Saved: name={}, color={}", name, color);
46    } else {
47        println!("✗ Not saved");
48    }
49}

Auto Trait Implementations§

§

impl Freeze for Input

§

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

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.