pub struct Input { /* private fields */ }Implementations§
Source§impl Input
impl Input
Sourcepub fn new(prompt: impl Into<String>) -> Self
pub fn new(prompt: impl Into<String>) -> Self
Examples found in repository?
More 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}Sourcepub fn run(self) -> Result<String>
pub fn run(self) -> Result<String>
Examples found in repository?
More 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> 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