You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
process::ExitStatus should have some kind of constructor #32713
B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-api[DEPRECATED; DO NOT USE]final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
Because ExitStatus 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 ExitStatus objects.
At the least there should be a way to create a success ExitStatus. Preferably, there would be a way to create various fail statuses too.
Reacted by Jakub Jirutka, Joel, Jack O'Connor, Lucas Pickup, Irfan Zainudin and Alex Murkoff
I've also wanted a basically "raw constructor" in the past. I'd be fine adding some std::os extensions which allow construction from a c_int or DWORD (i32 and u32)
This would help n00bs like me who start out by copying the example code and tweaking it:
let output = Command::new("sh").arg("-c").arg("echo hello").output().unwrap_or_else(|e| {panic!("failed to execute process: {}", e)});
This example is a special case that only happens to work if the unwrap_or_else contains a panic! or something else that immediately exits. Otherwise you need to create your own Output struct to return which is currently impossible.
B-unstableBlocker: Implemented in the nightly compiler and unstable.T-libs-api[DEPRECATED; DO NOT USE]final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
Activity
frewsxcv commentedon Apr 4, 2016
Should the constructor just take an
i32?alexcrichton commentedon Apr 4, 2016
I've also wanted a basically "raw constructor" in the past. I'd be fine adding some
std::osextensions which allow construction from ac_intorDWORD(i32andu32)jirutka commentedon Apr 26, 2016
+1
I’d like to extend
Command, but I cannot reuseOutputfor return value because I can’t constructExitStatus. :(alexcrichton commentedon Apr 26, 2016
I've opened a PR for this over at #33224
jirutka commentedon Apr 26, 2016
Great, thanks! 👍
std: Allow creating ExitStatus from raw values
Rollup merge of rust-lang#33224 - alexcrichton:create-exit-status, r=…
Rollup merge of rust-lang#33224 - alexcrichton:create-exit-status, r=…
Auto merge of #33224 - alexcrichton:create-exit-status, r=aturon
Rollup merge of rust-lang#33224 - alexcrichton:create-exit-status, r=…
joelself commentedon Jul 6, 2016
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
unwrap_or_elsecontains apanic!or something else that immediately exits. Otherwise you need to create your ownOutputstruct to return which is currently impossible.alexcrichton commentedon Jul 13, 2016
🔔 This issue is now entering a cycle-long final comment period for stabilization 🔔
alexcrichton commentedon Aug 11, 2016
Discussed recently, the libs team decided to stabilize.
Auto merge of #35607 - alexcrichton:stabilize-1.12, r=brson
Auto merge of #35607 - alexcrichton:stabilize-1.12, r=brson
std: Stabilize APIs for the 1.12 release
std: Stabilize APIs for the 1.12 release