use std::error::Error; use std::{io, io::Write}; fn prompt() -> Result<(), Box> { print!("> "); io::stdout().flush()?; Ok(()) } fn read_stdin() -> Result> { let mut buffer = String::new(); io::stdin().read_line(&mut buffer)?; Ok(buffer) } fn main() -> Result<(), Box> { loop { prompt()?; let user_input = read_stdin()?; if user_input.len() == 0 { // control-d or end of input. Needs to be specially handled before // the match because this is identical to whitespace after the trim. break; } match user_input.trim() { "" => {} "exit" => { break; } other_input => { println!("Unknown input {}", other_input); } } } Ok(()) }