diff options
| author | bors <bors@rust-lang.org> | 2016-05-09 14:04:08 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-09 14:04:08 -0700 |
| commit | 0e7cb8bc31413c9ea08c67c4d66318a7e9cbfb66 (patch) | |
| tree | 3692b59628ee281458df6b44b6cb661ca8c51f61 /src/libstd/sys/unix | |
| parent | faca79fc332f62b339aee5bd994b00e52d9ac051 (diff) | |
| parent | 7f09b1f6a64339370440025d50d0ad4a7f239734 (diff) | |
| download | rust-0e7cb8bc31413c9ea08c67c4d66318a7e9cbfb66.tar.gz rust-0e7cb8bc31413c9ea08c67c4d66318a7e9cbfb66.zip | |
Auto merge of #33224 - alexcrichton:create-exit-status, r=aturon
std: Allow creating ExitStatus from raw values Sometimes a process may be waited on externally from the standard library, in which case it can be useful to create a raw `ExitStatus` structure to return. This commit extends the existing Unix `ExitStatusExt` extension trait and adds a new Windows-specific `ExitStatusExt` extension trait to do this. The methods are currently called `ExitStatus::from_raw`. cc #32713
Diffstat (limited to 'src/libstd/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/ext/process.rs | 9 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index 7f31cf9f3bf..b0fed2f4694 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -132,6 +132,11 @@ impl CommandExt for process::Command { /// Unix-specific extensions to `std::process::ExitStatus` #[stable(feature = "rust1", since = "1.0.0")] pub trait ExitStatusExt { + /// Creates a new `ExitStatus` from the raw underlying `i32` return value of + /// a process. + #[unstable(feature = "exit_status_from", issue = "32713")] + fn from_raw(raw: i32) -> Self; + /// If the process was terminated by a signal, returns that signal. #[stable(feature = "rust1", since = "1.0.0")] fn signal(&self) -> Option<i32>; @@ -139,6 +144,10 @@ pub trait ExitStatusExt { #[stable(feature = "rust1", since = "1.0.0")] impl ExitStatusExt for process::ExitStatus { + fn from_raw(raw: i32) -> Self { + process::ExitStatus::from_inner(From::from(raw)) + } + fn signal(&self) -> Option<i32> { self.as_inner().signal() } diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 0500480add2..d5719167542 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -550,6 +550,12 @@ impl ExitStatus { } } +impl From<c_int> for ExitStatus { + fn from(a: c_int) -> ExitStatus { + ExitStatus(a) + } +} + impl fmt::Display for ExitStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(code) = self.code() { |
