summaryrefslogtreecommitdiffstats
path: root/tokio/src/stream/mod.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-01-31 21:18:11 -0800
committerGitHub <noreply@github.com>2020-01-31 21:18:11 -0800
commitab24a655adc1eb0d0c6951d5df2b815c671ac7d2 (patch)
treef32a689920d4d779fc2c30d87609e279847a291a /tokio/src/stream/mod.rs
parentc3d56b85c318c3cdc164558c722b9440d443dcea (diff)
stream: provide `StreamMap` utility (#2185)
`StreamMap` is similar to `StreamExt::merge` in that it combines source streams into a single merged stream that yields values in the order that they arrive from the source streams. However, `StreamMap` has a lot more flexibility in usage patterns. `StreamMap` can: - Merge an arbitrary number of streams. - Track which source stream the value was received from. - Handle inserting and removing streams from the set of managed streams at any point during iteration. All source streams held by `StreamMap` are indexed using a key. This key is included with the value when a source stream yields a value. The key is also used to remove the stream from the `StreamMap` before the stream has completed streaming. Because the `StreamMap` API moves streams during runtime, both streams and keys must be `Unpin`. In order to insert a `!Unpin` stream into a `StreamMap`, use `pin!` to pin the stream to the stack or `Box::pin` to pin the stream in the heap.
Diffstat (limited to 'tokio/src/stream/mod.rs')
-rw-r--r--tokio/src/stream/mod.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/tokio/src/stream/mod.rs b/tokio/src/stream/mod.rs
index 82771eee..3cc7e68f 100644
--- a/tokio/src/stream/mod.rs
+++ b/tokio/src/stream/mod.rs
@@ -50,6 +50,9 @@ pub use once::{once, Once};
mod pending;
pub use pending::{pending, Pending};
+mod stream_map;
+pub use stream_map::StreamMap;
+
mod try_next;
use try_next::TryNext;