From 753a385ad8668b85a392a6f29dafcc044bddc1af Mon Sep 17 00:00:00 2001 From: pragmaxim Date: Tue, 4 Jun 2024 12:27:24 +0200 Subject: [PATCH] cleanup --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 763df8b..4d70959 100644 --- a/README.md +++ b/README.md @@ -15,24 +15,27 @@ Either as a standalone stream operator or directly as a combinator. ```rust use futures::{stream, StreamExt}; use min_batch::MinBatchExt; + #[derive(Debug, PartialEq, Eq)] struct BlockOfTxs { name: char, txs_count: usize, } + #[tokio::main] async fn main() { let mut block_names: Vec = vec!['a', 'b', 'c', 'd']; let min_match_size = 3; - let batches: Vec> = stream::iter(1..=4) - .map(|x| BlockOfTxs { - name: block_names[x - 1], - txs_count: x, - }) - .min_batch(min_match_size, |block: &BlockOfTxs| block.txs_count) - .collect() - .await; - // Verify the batches + let batches: Vec> = + stream::iter(1..=4) + .map(|x| BlockOfTxs { + name: block_names[x - 1], + txs_count: x, + }) + .min_batch(min_match_size, |block: &BlockOfTxs| block.txs_count) + .collect() + .await; + assert_eq!(batches.len(), 3); // collect first two Blocks of Transactions until the total count of transactions is >= 3