I have this function in the main.rs
file in my code.
fn repl(vm: &VM) {
loop {
print!("> ");
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
vm::interpret(vm, &input);
}
}
When I run the program, the print!("> ")
line does not execute. However, when I take out the subsequent code it does. I've tried similar code from a different implementation I found online (see below), but even that does not work. The user input is working, however. Is there a reason why this happens? I'm new to Rust, so I don't have any ideas of what may be causing this.
Alternate Code Found:
fn repl(machine: &mut vm::VM) -> () {
loop {
print!("> ");
std::io::stdout().flush().unwrap();
let mut input = String::new();
let expression = std::io::stdin().read_line(&mut input);
match expression {
Ok(_) => (),
Err(_) => {
println!("Error!");
break;
}
}
vm::interpret(vm, &input);
}
}