I am trying to setup a chain of iterators and to be able to insert a running process in that chain.
So the process will take a Read for stdin and produce an Iterator of stdout.
Note that I can convert between Read and Iterator (itertools has the Iterator -> Read conversion).
I am stuck when trying to add proper error handling and could use some suggestions.
The only way I know how to stream a process is to return a BufReader of stdout and to spawn a thread to feed stdin to the proecess and also to view stderr as needed.
This all works, but problems arise when trying to detect errors. I also need to wait for the command to finish to inspect the error code. The problem is that I don’t think the Child interface is amenable to this: calling process.wait() on another thread ends up with borrowing violations.
The code is on github here:
Uncommenting the code in question gives borrowing errors.
error[E0382]: capture of partially moved value: `process` --> src/main.rs:78:30 | 66 | let stdout = process.stdout.expect("impossible! no stdout"); | -------------- value moved here ... 78 | let result = process.wait() | ^^^^^^^ value captured here after move
Note that I have not yet defined how to send this error back to the caller, It should be possible with a channel or a global panic handler.
A perfectly fine solution for me would be to point me to an alternative crate that implements this idea. I have not yet been able to come across it.