@@ -1964,47 +1964,32 @@ impl Child {
1964
1964
/// process, no destructors on the current stack or any other thread's stack
1965
1965
/// will be run. If a clean shutdown is needed it is recommended to only call
1966
1966
/// this function at a known point where there are no more destructors left
1967
- /// to run.
1967
+ /// to run; or, preferably, simply return a type implementing [`Termination`]
1968
+ /// (such as [`ExitCode`] or `Result`) from the `main` function and avoid this
1969
+ /// function altogether:
1970
+ ///
1971
+ /// ```
1972
+ /// # use std::io::Error as MyError;
1973
+ /// fn main() -> Result<(), MyError> {
1974
+ /// // ...
1975
+ /// Ok(())
1976
+ /// }
1977
+ /// ```
1968
1978
///
1969
1979
/// ## Platform-specific behavior
1970
1980
///
1971
1981
/// **Unix**: On Unix-like platforms, it is unlikely that all 32 bits of `exit`
1972
1982
/// will be visible to a parent process inspecting the exit code. On most
1973
1983
/// Unix-like platforms, only the eight least-significant bits are considered.
1974
1984
///
1975
- /// # Examples
1976
- ///
1977
- /// Due to this function’s behavior regarding destructors, a conventional way
1978
- /// to use the function is to extract the actual computation to another
1979
- /// function and compute the exit code from its return value:
1980
- ///
1981
- /// ```
1982
- /// fn run_app() -> Result<(), ()> {
1983
- /// // Application logic here
1984
- /// Ok(())
1985
- /// }
1986
- ///
1987
- /// fn main() {
1988
- /// std::process::exit(match run_app() {
1989
- /// Ok(_) => 0,
1990
- /// Err(err) => {
1991
- /// eprintln!("error: {err:?}");
1992
- /// 1
1993
- /// }
1994
- /// });
1995
- /// }
1996
- /// ```
1997
- ///
1998
- /// Due to [platform-specific behavior], the exit code for this example will be
1999
- /// `0` on Linux, but `256` on Windows:
1985
+ /// For example, the exit code for this example will be `0` on Linux, but `256`
1986
+ /// on Windows:
2000
1987
///
2001
1988
/// ```no_run
2002
1989
/// use std::process;
2003
1990
///
2004
1991
/// process::exit(0x0100);
2005
1992
/// ```
2006
- ///
2007
- /// [platform-specific behavior]: #platform-specific-behavior
2008
1993
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2009
1994
pub fn exit ( code : i32 ) -> ! {
2010
1995
crate :: rt:: cleanup ( ) ;
0 commit comments