Skip to main content

input_trim

Function input_trim 

Source
pub fn input_trim(
    comment: &str,
    trim_whitespace: bool,
) -> Result<String, InputError>
Expand description

Reads a line of input with configurable trimming behavior.

§Arguments

  • comment - The prompt text to display
  • trim_whitespace - Whether to trim leading/trailing whitespace

§Returns

  • Ok(String) - The input string (trimmed or not based on setting)
  • Err(InputError) - An error if stdout write/flush or stdin read fails

§Examples

use input_py::input_trim;

// Preserve whitespace
match input_trim("Enter text", false) {
    Ok(text) => println!("Raw input: '{}'", text),
    Err(e) => eprintln!("Error: {}", e),
}

// Trim whitespace (default behavior)
match input_trim("Enter text", true) {
    Ok(text) => println!("Trimmed input: '{}'", text),
    Err(e) => eprintln!("Error: {}", e),
}