@@ -1648,8 +1648,8 @@ impl crate::error::Error for ExitStatusError {}
1648
1648
/// This type represents the status code the current process can return
1649
1649
/// to its parent under normal termination.
1650
1650
///
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
1653
1653
/// `PartialEq`, `Eq`, or `Hash`. Instead the standard library provides the
1654
1654
/// canonical `SUCCESS` and `FAILURE` exit codes as well as `From<u8> for
1655
1655
/// ExitCode` for constructing other arbitrary exit codes.
@@ -1673,21 +1673,39 @@ impl crate::error::Error for ExitStatusError {}
1673
1673
/// compatibility differences and their expected usage; it is not generally
1674
1674
/// possible to exactly reproduce an ExitStatus from a child for the current
1675
1675
/// 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
+ /// ```
1676
1694
#[ derive( Clone , Copy , Debug ) ]
1677
1695
#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
1678
1696
pub struct ExitCode ( imp:: ExitCode ) ;
1679
1697
1680
1698
#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
1681
1699
impl ExitCode {
1682
- /// The canonical ExitCode for successful termination on this platform.
1700
+ /// The canonical ` ExitCode` for successful termination on this platform.
1683
1701
///
1684
1702
/// Note that a `()`-returning `main` implicitly results in a successful
1685
1703
/// termination, so there's no need to return this from `main` unless
1686
1704
/// you're also returning other possible codes.
1687
1705
#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
1688
1706
pub const SUCCESS : ExitCode = ExitCode ( imp:: ExitCode :: SUCCESS ) ;
1689
1707
1690
- /// The canonical ExitCode for unsuccessful termination on this platform.
1708
+ /// The canonical ` ExitCode` for unsuccessful termination on this platform.
1691
1709
///
1692
1710
/// If you're only returning this and `SUCCESS` from `main`, consider
1693
1711
/// instead returning `Err(_)` and `Ok(())` respectively, which will
@@ -1697,27 +1715,28 @@ impl ExitCode {
1697
1715
}
1698
1716
1699
1717
impl 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
1701
1719
// all usecases, for example windows seems to use u32, unix uses the 8-15th bits of an i32, we
1702
1720
// likely want to isolate users anything that could restrict the platform specific
1703
1721
// representation of an ExitCode
1704
1722
//
1705
1723
// 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
1707
1725
#[ unstable(
1708
1726
feature = "process_exitcode_internals" ,
1709
1727
reason = "exposed only for libstd" ,
1710
1728
issue = "none"
1711
1729
) ]
1712
1730
#[ inline]
1731
+ #[ doc( hidden) ]
1713
1732
pub fn to_i32 ( self ) -> i32 {
1714
1733
self . 0 . as_i32 ( )
1715
1734
}
1716
1735
}
1717
1736
1718
1737
#[ stable( feature = "process_exitcode" , since = "1.60.0" ) ]
1719
1738
impl From < u8 > for ExitCode {
1720
- /// Construct an exit code from an arbitrary u8 value.
1739
+ /// Construct an `ExitCode` from an arbitrary u8 value.
1721
1740
fn from ( code : u8 ) -> Self {
1722
1741
ExitCode ( imp:: ExitCode :: from ( code) )
1723
1742
}
0 commit comments