]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #42024 - citizen428:docs/update-exitstatus, r=steveklabnik
authorMark Simulacrum <mark.simulacrum@gmail.com>
Fri, 19 May 2017 20:16:16 +0000 (14:16 -0600)
committerGitHub <noreply@github.com>
Fri, 19 May 2017 20:16:16 +0000 (14:16 -0600)
Add documentation for `ExitStatus`

As requested in #29370. r? @steveklabnik

src/libstd/process.rs

index 3896fc20a2dde12924ac2c477b6013f0459d2a65..d0e7defbbbb9a15f0b9af79925d319c8d8e22d59 100644 (file)
@@ -754,6 +754,13 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 /// Describes the result of a process after it has terminated.
+///
+/// This `struct` is used to represent the exit status of a child process.
+/// Child processes are created via the [`Command`] struct and their exit
+/// status is exposed through the [`status`] method.
+///
+/// [`Command`]: struct.Command.html
+/// [`status`]: struct.Command.html#method.status
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
 #[stable(feature = "process", since = "1.0.0")]
 pub struct ExitStatus(imp::ExitStatus);
@@ -788,6 +795,22 @@ pub fn success(&self) -> bool {
     /// On Unix, this will return `None` if the process was terminated
     /// by a signal; `std::os::unix` provides an extension trait for
     /// extracting the signal and other details from the `ExitStatus`.
+    ///
+    /// # Examples
+    ///
+    /// ```no_run
+    /// use std::process::Command;
+    ///
+    /// let status = Command::new("mkdir")
+    ///                      .arg("projects")
+    ///                      .status()
+    ///                      .expect("failed to execute mkdir");
+    ///
+    /// match status.code() {
+    ///     Some(code) => println!("Exited with status code: {}", code),
+    ///     None       => println!("Process terminated by signal")
+    /// }
+    /// ```
     #[stable(feature = "process", since = "1.0.0")]
     pub fn code(&self) -> Option<i32> {
         self.0.code()