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 {
17411741 /// behavior][exit#platform-specific-behavior]). `ExitCode` exists because of this; only
17421742 /// `ExitCode`s that are valid on all platforms can be created, so those problems don't exist
17431743 /// 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+ /// ```
17441767 #[ unstable( feature = "exitcode_exit_method" , issue = "none" ) ]
17451768 pub fn exit_process ( self ) -> ! {
17461769 exit ( self . to_i32 ( ) )
You can’t perform that action at this time.
0 commit comments