[Rust] Exit a program using std::process in Rust
In this lesson we'll learn how to exit a program using the std::process
module in Rust and it's exit()
method.
use std::io;
use std::process;
fn main() {
let mut first = String::new();
io::stdin().read_line(&mut first).unwrap();
let a:u32;
match first.trim().parse() {
Ok(val) => {
a = val;
},
Err(_err) => {
println!("This is not a valid number");
process::exit(1);
}
}
}