Streaming json deserialiser of a child process and see the exit code?

Hi, I'm streaming deserialising some json with serde_json, which takes in a reader:


As you can see I am handing it the stdout of a child process.

But now my child process is partially consumed so I can't wait() for it to exit and find out what the exit code is. This seems a pretty common problem so I figured I'd post it here so the answers help others as well as me.

Is there a way I can have my streaming deserialised cake and eat it? (I.e. can I mutably lend the stdout to a steraming json deserialiser somehow? (or is there some level at which I can clone or wrap in an Rc?)


I would try taking the stdout handle with Option::take, leaving the process struct in tact, just with the stdout field set to None.

Perfect. I was assuming that taking the stream out of the struct would in some way hurt the child process object but it seems fine with that moved out.