From 220cb6e96ba4b4df9147e41cfe5d001bd0a204de Mon Sep 17 00:00:00 2001 From: Yosh Date: Fri, 12 Apr 2024 01:40:23 +0200 Subject: [PATCH] Implement feedback from review Co-Authored-By: Consoli --- src/concurrent_stream/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/concurrent_stream/mod.rs b/src/concurrent_stream/mod.rs index 1ac985f..46de45b 100644 --- a/src/concurrent_stream/mod.rs +++ b/src/concurrent_stream/mod.rs @@ -1,4 +1,40 @@ //! Concurrent execution of streams +//! +//! # Examples +//! +//! **Concurrently process items in a collection** +//! +//! ```rust +//! use futures_concurrency::prelude::*; +//! +//! # futures::executor::block_on(async { +//! let v: Vec<_> = vec!["chashu", "nori"] +//! .into_co_stream() +//! .map(|msg| async move { format!("hello {msg}") }) +//! .collect() +//! .await; +//! +//! assert_eq!(v, &["hello chashu", "hello nori"]); +//! # }); +//! ``` +//! +//! **Concurrently process items in a stream** +//! +//! ```rust +//! use futures_concurrency::prelude::*; +//! use futures_lite::stream; +//! +//! # futures::executor::block_on(async { +//! let v: Vec<_> = stream::repeat("chashu") +//! .co() +//! .take(2) +//! .map(|msg| async move { format!("hello {msg}") }) +//! .collect() +//! .await; +//! +//! assert_eq!(v, &["hello chashu", "hello chashu"]); +//! # }); +//! ``` mod enumerate; mod for_each; diff --git a/src/lib.rs b/src/lib.rs index 9fc2637..d13f6aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ //! # }); //! ``` //! -//! **Concurrently process items in a stream** +//! **Concurrently process items in a collection** //! //! ```rust //! use futures_concurrency::prelude::*; @@ -110,7 +110,7 @@ //! The following streams implementations are provided by `futures-concurrency`: //! //! - [`StreamGroup`][stream::StreamGroup]: A growable group of streams which operate as a single unit. -//! - [`ConcurrentStream`][concurrent_stream::ConcurrentStream]: An asynchronous stream which can concurrently process items. +//! - [`ConcurrentStream`][concurrent_stream::ConcurrentStream]: A trait for asynchronous streams which can concurrently process items. //! - `tuple`: [`chain`][stream::Chain#impl-Chain-for-(A,+B)], [`merge`][stream::Merge#impl-Merge-for-(A,+B)], [`zip`][stream::Zip#impl-Zip-for-(A,+B)] //! - `array`: [`chain`][stream::Chain#impl-Chain-for-\[Fut;+N\]], [`merge`][stream::Merge#impl-Merge-for-\[Fut;+N\]], [`zip`][stream::Zip#impl-Zip-for-\[Fut;+N\]] //! - `Vec`: [`chain`][stream::Chain#impl-Chain-for-Vec], [`merge`][stream::Merge#impl-Merge-for-Vec], [`zip`][stream::Zip#impl-Zip-for-Vec]