Skip to main content

input_with_default

Function input_with_default 

Source
pub fn input_with_default(
    comment: &str,
    default: &str,
) -> Result<String, InputError>
Expand description

Reads a line of input with a default value if nothing is entered.

§Arguments

  • comment - The prompt text to display
  • default - The default value to return if the user enters nothing

§Returns

  • Ok(String) - The input string or default value
  • Err(InputError) - An error if stdout write/flush or stdin read fails

§Examples

use input_py::input_with_default;

match input_with_default("Enter port", "8080") {
    Ok(port) => println!("Using port: {}", port),
    Err(e) => eprintln!("Error: {}", e),
}