I am in the process of writing a bash
clone in Rust. I need to have my program exit when the user types exit
. In previous iterations of my program, before I added more complicated features, I used return
to get out of the loop that was prompting the user for input. This logic is now in a function, because of the way I am implementing built in shell functions, so when I return
it just jumps out of the function back into the control loop, instead of short-circuiting the control loop and ending the program.
I realize that I could probably return a boolean when the user types exit
and exit the loop, but I would like to at least know if Rust has a way to terminate programs early, similar to Java's System.exit()
, as this is useful for certain types of programs.