tokio-process-stream is a simple crate that wraps a [tokio::process
] into a
[tokio::stream
]
Having a stream interface to processes is useful when we have multiple sources of data that we want to merge and start processing from a single entry point.
This crate provides a [tokio_stream::Stream
] wrapper for [tokio::process::Child
]. The
main struct is [ProcessStream
], which implements the trait, yielding one [Item
] enum at
a time, each containing one line from either stdout ([Item::Stdout
]) or stderr
([Item::Stderr
]) of the underlying process until it exits. At this point, the stream
yields a single [Item::Done
] and finishes.
Example usage:
```rust use tokioprocessstream::ProcessStream; use tokio::process::Command; use tokio_stream::StreamExt; use std::error::Error;
async fn main() -> Result<(), Box
let sleep_procstream = ProcessStream::try_from(sleep_cmd)?;
let ls_procstream = ProcessStream::try_from(ls_cmd)?;
let mut procstream = sleep_procstream.merge(ls_procstream);
while let Some(item) = procstream.next().await {
println!("{:?}", item);
}
Ok(())
} ```