@@ -1648,8 +1648,8 @@ impl crate::error::Error for ExitStatusError {}
16481648/// This type represents the status code the current process can return
16491649/// to its parent under normal termination.
16501650///
1651- /// ExitCode is intended to be consumed only by the standard library (via
1652- /// `Termination::report()`), and intentionally does not provide accessors like
1651+ /// ` ExitCode` is intended to be consumed only by the standard library (via
1652+ /// [ `Termination::report()`] ), and intentionally does not provide accessors like
16531653/// `PartialEq`, `Eq`, or `Hash`. Instead the standard library provides the
16541654/// canonical `SUCCESS` and `FAILURE` exit codes as well as `From<u8> for
16551655/// ExitCode` for constructing other arbitrary exit codes.
@@ -1673,21 +1673,39 @@ impl crate::error::Error for ExitStatusError {}
16731673/// compatibility differences and their expected usage; it is not generally
16741674/// possible to exactly reproduce an ExitStatus from a child for the current
16751675/// process after the fact.
1676+ ///
1677+ /// # Examples
1678+ ///
1679+ /// `ExitCode` can be returned from the `main` function of a crate, as it implements
1680+ /// [`Termination`]:
1681+ ///
1682+ /// ```
1683+ /// use std::process::ExitCode;
1684+ /// # fn check_foo() -> bool { true }
1685+ ///
1686+ /// fn main() -> ExitCode {
1687+ /// if !check_foo() {
1688+ /// return ExitCode::from(42);
1689+ /// }
1690+ ///
1691+ /// ExitCode::SUCCESS
1692+ /// }
1693+ /// ```
16761694#[ derive( Clone , Copy , Debug ) ]
16771695#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
16781696pub struct ExitCode ( imp:: ExitCode ) ;
16791697
16801698#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
16811699impl ExitCode {
1682- /// The canonical ExitCode for successful termination on this platform.
1700+ /// The canonical ` ExitCode` for successful termination on this platform.
16831701 ///
16841702 /// Note that a `()`-returning `main` implicitly results in a successful
16851703 /// termination, so there's no need to return this from `main` unless
16861704 /// you're also returning other possible codes.
16871705 #[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
16881706 pub const SUCCESS : ExitCode = ExitCode ( imp:: ExitCode :: SUCCESS ) ;
16891707
1690- /// The canonical ExitCode for unsuccessful termination on this platform.
1708+ /// The canonical ` ExitCode` for unsuccessful termination on this platform.
16911709 ///
16921710 /// If you're only returning this and `SUCCESS` from `main`, consider
16931711 /// instead returning `Err(_)` and `Ok(())` respectively, which will
@@ -1697,27 +1715,28 @@ impl ExitCode {
16971715}
16981716
16991717impl ExitCode {
1700- // This should not be stabilized when stabilizing ExitCode, we don't know that i32 will serve
1718+ // This is private/perma-unstable because ExitCode is opaque; we don't know that i32 will serve
17011719 // all usecases, for example windows seems to use u32, unix uses the 8-15th bits of an i32, we
17021720 // likely want to isolate users anything that could restrict the platform specific
17031721 // representation of an ExitCode
17041722 //
17051723 // More info: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
1706- /// Convert an ExitCode into an i32
1724+ /// Convert an ` ExitCode` into an i32
17071725 #[ unstable(
17081726 feature = "process_exitcode_internals" ,
17091727 reason = "exposed only for libstd" ,
17101728 issue = "none"
17111729 ) ]
17121730 #[ inline]
1731+ #[ doc( hidden) ]
17131732 pub fn to_i32 ( self ) -> i32 {
17141733 self . 0 . as_i32 ( )
17151734 }
17161735}
17171736
17181737#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
17191738impl From < u8 > for ExitCode {
1720- /// Construct an exit code from an arbitrary u8 value.
1739+ /// Construct an `ExitCode` from an arbitrary u8 value.
17211740 fn from ( code : u8 ) -> Self {
17221741 ExitCode ( imp:: ExitCode :: from ( code) )
17231742 }
0 commit comments