diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-02-05 09:14:34 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-05 09:14:34 -0500 |
| commit | 001bfb9e566b92b9336eb210b270c9404626d89f (patch) | |
| tree | f4e77ba967a4f57fa7154f2eb0e2f49cea1a4775 /src/libstd/process.rs | |
| parent | 696f5c1fc695494053709ae3b18b4c6a65b619a6 (diff) | |
| parent | c2eab73788a066384f3d1facca1ca7b9fc214962 (diff) | |
| download | rust-001bfb9e566b92b9336eb210b270c9404626d89f.tar.gz rust-001bfb9e566b92b9336eb210b270c9404626d89f.zip | |
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.
Diffstat (limited to 'src/libstd/process.rs')
| -rw-r--r-- | src/libstd/process.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 5af4ba53bf9..23a53d777a5 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -959,10 +959,27 @@ impl Child { /// /// # Examples /// +/// Due to this function’s 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: +/// /// ``` -/// use std::process; +/// use std::io::{self, Write}; +/// +/// fn run_app() -> Result<(), ()> { +/// // Application logic here +/// Ok(()) +/// } /// -/// process::exit(0); +/// 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 |
