Crate io_prompt_prototype[][src]

Expand description

A prototype for io::prompt, io::promptln, and io::read_line.


use io_prompt_prototype::{prompt, promptln};

let num: u16 = prompt!("What's your favorite number? >").parse()?;
println!("Oh, cool: {}!", num);

let variable = "snack";
let res = promptln!("What's your favorite {}? >", variable);
println!("We love {} too!", res);

Design Considerations

A survey of existing prompt functions can be found here This library makes several tradeoffs in its design:

  • Just like the std::io::println! family of macros, the prompt macros panic in the case of an error.
  • The prompt macros don’t support parsing of values in-place. Users are encouraged to .parse instead.
  • The prompt family of macros only support reading a single line at the time and assigning it to a value.
  • The prompt family of macros doesn’t support rich input types such as passwords or dropdowns. This functionality is expected to be provided through

This library is split into two parts: a convenient read_line function which is a shorthand for calling Stdin::read_line and reading into a new string. And the prompt! family of macros which support reading from writing to stdout/stderr, and reading a value from stdin.

The focus for the prompt family of macros is on simplicity: its goal is to make it convenient to write quick prompts inside Rust programs in a way that feels similar to using println!. It does not try and cover parsing rules by introducing a new DSL. Such a DSL almost certainly needs to have regex-like capabilities, and would be nearly impossible to stabilize.



Prints to the standard error. Then reads a line of input.


Prints to the standard error, with a newline. Then reads a line of input.


Prints to the standard output. Then reads a line of input.


Prints to the standard output, with a newline. Then reads a line of input.



Reads a line of input from stdin.