Chooce video playback speed
speed:1

Exit a program using std::process in Rust

InstructorPascal Precht

Share this video with your friends

Send Tweet

In this lesson we'll learn how to exit a program using the std::process module in Rust and it's exit() method.

Instructor: To exit a program, use the process module from Rust standard library, and then call process::exit, which will exit the program with an exit code. Any exit code that is not 0means that the program has exit with an error.

We also no longer need to make our a variable mutable and assign an initial value, because the program will either assign an initial value, in case parsing was successful, or in case of an error it will exit the program.

When we run this code and enter a fault c value, we now see that our program successfully exits.