Select

Struct Select 

Source
pub struct Select<T> { /* private fields */ }

Implementations§

Source§

impl<T> Select<T>

Source

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

Examples found in repository?
examples/select_basic.rs (line 6)
3fn main() {
4    println!("=== Select Component Demo ===\n");
5
6    let result = Select::new("Choose a color:")
7        .option("Red", "red")
8        .option("Green", "green")
9        .option("Blue", "blue")
10        .option("Yellow", "yellow")
11        .run();
12
13    match result {
14        Ok(color) => println!("\nYou chose: {}", color),
15        Err(e) => eprintln!("\nError: {}", e),
16    }
17}
More examples
Hide additional examples
examples/combined.rs (line 18)
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 option(self, label: impl Into<String>, value: T) -> Self

Examples found in repository?
examples/select_basic.rs (line 7)
3fn main() {
4    println!("=== Select Component Demo ===\n");
5
6    let result = Select::new("Choose a color:")
7        .option("Red", "red")
8        .option("Green", "green")
9        .option("Blue", "blue")
10        .option("Yellow", "yellow")
11        .run();
12
13    match result {
14        Ok(color) => println!("\nYou chose: {}", color),
15        Err(e) => eprintln!("\nError: {}", e),
16    }
17}
More examples
Hide additional examples
examples/combined.rs (line 19)
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 options(self, options: Vec<(String, T)>) -> Self

Source

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

Examples found in repository?
examples/select_basic.rs (line 11)
3fn main() {
4    println!("=== Select Component Demo ===\n");
5
6    let result = Select::new("Choose a color:")
7        .option("Red", "red")
8        .option("Green", "green")
9        .option("Blue", "blue")
10        .option("Yellow", "yellow")
11        .run();
12
13    match result {
14        Ok(color) => println!("\nYou chose: {}", color),
15        Err(e) => eprintln!("\nError: {}", e),
16    }
17}
More examples
Hide additional examples
examples/combined.rs (line 22)
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<T> Freeze for Select<T>

§

impl<T> RefUnwindSafe for Select<T>
where T: RefUnwindSafe,

§

impl<T> Send for Select<T>
where T: Send,

§

impl<T> Sync for Select<T>
where T: Sync,

§

impl<T> Unpin for Select<T>
where T: Unpin,

§

impl<T> UnwindSafe for Select<T>
where T: UnwindSafe,

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.