3 releases
0.0.3 | Dec 9, 2022 |
---|---|
0.0.2 | Dec 9, 2022 |
0.0.1 | Dec 8, 2022 |
#2448 in Rust patterns
11KB
177 lines
Tokio-Stream-Extra
A crate that extends the Stream trait. For more details about streams please check the tokio-stream crate as well as StreamExt trait documentation.
Examples
Split
Splits this stream's items at a separation item. The separation item
is determined by provided closure. A stream of vectors of item type will be returned,
which will yield elements until the closure returns None
.
[tokio::main]
async fn main() {
use tokio_stream::{self as stream, StreamExt};
use tokio_stream_extra::StreamExtra;
let stream = stream::iter(vec![1,2,0,3,4,0]);
let mut stream = stream.split(|x| x == &0);
assert_eq!(stream.next().await, Some(vec![1,2]));
assert_eq!(stream.next().await, Some(vec![3,4]));
Tests
Test Coverage
To get the test coverage, I use the grcov. See the instructions steps.
export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE="./coverage/lib-%p-%m.profraw"
cargo build
cargo test
grcov ./coverage -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/
open ./target/debug/coverage/index.html
Property Based Testing
The library is using property based testing. It uses the quickcheck crate.
About
Code designed and written on the beautiful island of Saaremaa, Estonia.
Dependencies
~0.9–1.6MB
~31K SLoC