soenkehahn / cradle

Rust library for running child processes
Creative Commons Zero v1.0 Universal
38 stars 5 forks source link

Don't clone `ChildOutput` for tuple `Output`s #179

Closed soenkehahn closed 3 years ago

soenkehahn commented 3 years ago

Before this PR we would pass ChildOutput not by reference and then had to clone it in a few places. For example in the tuple implementations. Consider this example:

let (StdoutUntrimmed(a), Stderr(b), Status(c)) = run!("...");

Here we would clone ChildOutput (including the complete captured stdout and stderr) 3 times, for every tuple component.

This PR changes that to only clone stdout once when StdoutUntrimmed is created and stderr once when Stderr is created.

This is not strictly better though. In this example we would not have to clone before, but now we do:

let StdoutUntrimmed(a) = run!("...");

I still think that this is probably a good change.

casey commented 3 years ago

Looks good to me, definitely agree that it's better, and less surprising.