pub struct Select<T> { /* private fields */ }Implementations§
Source§impl<T> Select<T>
impl<T> Select<T>
Sourcepub fn new(prompt: impl Into<String>) -> Self
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
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}Sourcepub fn option(self, label: impl Into<String>, value: T) -> Self
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
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}pub fn options(self, options: Vec<(String, T)>) -> Self
Sourcepub fn run(self) -> Result<T>
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
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more