Rollup merge of #38518 - nagisa:exec-doc, r=alexcrichton

Expand documentation of process::exit and exec

Show a conventional way to use process::exit when destructors are considered important and also
mention that the same caveats wrt destructors apply to exec as well.
This commit is contained in:
Corey Farwell
2017-02-05 09:14:34 -05:00
committed by GitHub
2 changed files with 30 additions and 3 deletions

View File

@@ -959,10 +959,27 @@ impl Child {
///
/// # Examples
///
/// ```
/// use std::process;
/// Due to this functions behavior regarding destructors, a conventional way
/// to use the function is to extract the actual computation to another
/// function and compute the exit code from its return value:
///
/// process::exit(0);
/// ```
/// use std::io::{self, Write};
///
/// fn run_app() -> Result<(), ()> {
/// // Application logic here
/// Ok(())
/// }
///
/// fn main() {
/// ::std::process::exit(match run_app() {
/// Ok(_) => 0,
/// Err(err) => {
/// writeln!(io::stderr(), "error: {:?}", err).unwrap();
/// 1
/// }
/// });
/// }
/// ```
///
/// Due to [platform-specific behavior], the exit code for this example will be