Skip to content

Commit b2fc7b1

Browse files
committed
Add documentation for ExitStatus
As requested in #29370.
1 parent fb6f845 commit b2fc7b1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libstd/process.rs

+23
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ impl fmt::Debug for Stdio {
754754
}
755755

756756
/// Describes the result of a process after it has terminated.
757+
///
758+
/// This `struct` is used to represent the exit status of a child process.
759+
/// Child processes are created via the [`Command`] struct and their exit
760+
/// status is exposed through the [`status`] method.
761+
///
762+
/// [`Command`]: struct.Command.html
763+
/// [`status`]: struct.Command.html#method.status
757764
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
758765
#[stable(feature = "process", since = "1.0.0")]
759766
pub struct ExitStatus(imp::ExitStatus);
@@ -788,6 +795,22 @@ impl ExitStatus {
788795
/// On Unix, this will return `None` if the process was terminated
789796
/// by a signal; `std::os::unix` provides an extension trait for
790797
/// extracting the signal and other details from the `ExitStatus`.
798+
///
799+
/// # Examples
800+
///
801+
/// ```no_run
802+
/// use std::process::Command;
803+
///
804+
/// let status = Command::new("mkdir")
805+
/// .arg("projects")
806+
/// .status()
807+
/// .expect("failed to execute mkdir");
808+
///
809+
/// match status.code() {
810+
/// Some(code) => println!("Exited with status code: {}", code),
811+
/// None => println!("Process terminated by signal")
812+
/// }
813+
/// ```
791814
#[stable(feature = "process", since = "1.0.0")]
792815
pub fn code(&self) -> Option<i32> {
793816
self.0.code()

0 commit comments

Comments
 (0)