Change:
Because has a private field it is impossible to create one in user code, one must actually execute a process. This prevents testing/mocking. My use case is that I have some function which runs a process and generates data, however, for testing I want to mock the test run and just return a success exit status and some data. I can't do that because I can't create my own objects. At the least there should be a way to create a success . Preferably, there would be a way to create various fail statuses too.
Should the constructor just take an ?
I've also wanted a basically "raw constructor" in the past. I'd be fine adding some extensions which allow construction from a or ( and )
+1 I’d like to extend , but I cannot reuse for return value because I can’t construct . :(
I've opened a PR for this over at
Great, thanks! :+1:
This would help n00bs like me who start out by copying the example code and tweaking it: This example is a special case that only happens to work if the contains a or something else that immediately exits. Otherwise you need to create your own struct to return which is currently impossible.
This issue is now entering a cycle-long final comment period for stabilization
Discussed recently, the libs team decided to stabilize.

Discussion:
fn as_inner(&self) -> &imp::ExitStatus { &self.0 } } <ins> impl FromInner<imp::ExitStatus> for ExitStatus { fn from_inner(s: imp::ExitStatus) -> ExitStatus { ExitStatus(s) } } </ins> #[stable(feature = "process", since = "1.0.0")] impl fmt::Display for ExitStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

/// Unix-specific extensions to `std::process::ExitStatus` #[stable(feature = "rust1", since = "1.0.0")] pub trait ExitStatusExt { <ins> /// 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; </ins> /// If the process was terminated by a signal, returns that signal. #[stable(feature = "rust1", since = "1.0.0")] fn signal(&self) -> Option<i32>;

#[stable(feature = "rust1", since = "1.0.0")] impl ExitStatusExt for process::ExitStatus { <ins> fn from_raw(raw: i32) -> Self { process::ExitStatus::from_inner(From::from(raw)) } </ins> fn signal(&self) -> Option<i32> { self.as_inner().signal() }

} } <ins> impl From<c_int> for ExitStatus { fn from(a: c_int) -> ExitStatus { ExitStatus(a) } } </ins> impl fmt::Display for ExitStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(code) = self.code() {

self.into_inner().into_handle().into_raw() as *mut _ } } <ins> /// Windows-specific extensions to `std::process::ExitStatus` #[unstable(feature = "exit_status_from", issue = "32713")] pub trait ExitStatusExt { /// Creates a new `ExitStatus` from the raw underlying `u32` return value of /// a process. fn from_raw(raw: u32) -> Self; } #[stable(feature = "rust1", since = "1.0.0")] impl ExitStatusExt for process::ExitStatus { fn from_raw(raw: u32) -> Self { process::ExitStatus::from_inner(From::from(raw)) } } </ins>

} } <ins> impl From<c::DWORD> for ExitStatus { fn from(u: c::DWORD) -> ExitStatus { ExitStatus(u) } } </ins> impl fmt::Display for ExitStatus { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "exit code: {}", self.0)