diff options
| author | Noa <coolreader18@gmail.com> | 2022-03-27 00:50:24 -0500 |
|---|---|---|
| committer | Noa <coolreader18@gmail.com> | 2022-03-30 21:35:42 -0500 |
| commit | 8ff0fd1fa94c6e238a2baab4e2ff86a08e77dbe1 (patch) | |
| tree | 4fdc1ec47165883464e9cd787c3cb344364e1856 /library/std/src/process.rs | |
| parent | 1446d17b8f4bd3ff8dbfb129a7674165e06f9f4c (diff) | |
| download | rust-8ff0fd1fa94c6e238a2baab4e2ff86a08e77dbe1.tar.gz rust-8ff0fd1fa94c6e238a2baab4e2ff86a08e77dbe1.zip | |
Add ExitCode::exit_process()
Diffstat (limited to 'library/std/src/process.rs')
| -rw-r--r-- | library/std/src/process.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs index d3c8d864b0c..d2994e56b13 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1725,6 +1725,26 @@ impl ExitCode { /// return the same codes (but will also `eprintln!` the error). #[stable(feature = "process_exitcode", since = "1.60.0")] pub const FAILURE: ExitCode = ExitCode(imp::ExitCode::FAILURE); + + /// Exit the current process with the given `ExitCode`. + /// + /// Note that this has the same caveats as [`process::exit()`][exit], namely that this function + /// terminates the process immediately, so no destructors on the current stack or any other + /// thread's stack will be run. If a clean shutdown is needed, it is recommended to simply + /// return this ExitCode from the `main` function, as demonstrated in the [type + /// documentation](#examples). + /// + /// # Differences from `process::exit()` + /// + /// `process::exit()` accepts any `i32` value as the exit code for the process; however, there + /// are platforms that only use a subset of that value (see [`process::exit` platform-specific + /// behavior][exit#platform-specific-behavior]). `ExitCode` exists because of this; only + /// `ExitCode`s that are valid on all platforms can be created, so those problems don't exist + /// with this method. + #[unstable(feature = "exitcode_exit_method", issue = "none")] + pub fn exit_process(self) -> ! { + exit(self.to_i32()) + } } impl ExitCode { |
