This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1741,6 +1741,29 @@ impl ExitCode {
1741
1741
/// behavior][exit#platform-specific-behavior]). `ExitCode` exists because of this; only
1742
1742
/// `ExitCode`s that are valid on all platforms can be created, so those problems don't exist
1743
1743
/// with this method.
1744
+ ///
1745
+ /// # Examples
1746
+ ///
1747
+ /// ```
1748
+ /// #![feature(exitcode_exit_method)]
1749
+ /// # use std::process::ExitCode;
1750
+ /// # use std::fmt;
1751
+ /// # enum UhOhError { GenericProblem, Specific, WithCode { exit_code: ExitCode, _x: () } }
1752
+ /// # impl fmt::Display for UhOhError {
1753
+ /// # fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { unimplemented!() }
1754
+ /// # }
1755
+ /// // there's no way to gracefully recover from an UhOhError, so we just
1756
+ /// // print a message and exit
1757
+ /// fn handle_unrecoverable_error(err: UhOhError) -> ! {
1758
+ /// eprintln!("UH OH! {err}");
1759
+ /// let code = match err {
1760
+ /// UhOhError::GenericProblem => ExitCode::FAILURE,
1761
+ /// UhOhError::Specific => ExitCode::from(3),
1762
+ /// UhOhError::WithCode { exit_code, .. } => exit_code,
1763
+ /// };
1764
+ /// code.exit_process()
1765
+ /// }
1766
+ /// ```
1744
1767
#[ unstable( feature = "exitcode_exit_method" , issue = "none" ) ]
1745
1768
pub fn exit_process ( self ) -> ! {
1746
1769
exit ( self . to_i32 ( ) )
You can’t perform that action at this time.
0 commit comments