#async #stream #streams #shared

shared_stream

A crate for easily cloneable streams

3 unstable releases

0.2.0 Mar 12, 2021
0.1.1 Mar 3, 2021
0.1.0 Mar 2, 2021

#308 in Asynchronous

30 downloads per month

AGPL-3.0+

16KB
225 lines

shared_stream is a crate for easily cloneable streams.

Usage

Add this to your Cargo.toml:

[dependencies]
shared_stream = "0.2"

Now, you can use shared_stream:

use shared_stream::Share;

let shared = stream::iter(1..=3).shared();

License

This crate is published under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.


lib.rs:

A crate for easily cloneable [Stream]s, similar to FutureExt::shared.

Examples

# futures::executor::block_on(async {
use futures::stream::{self, StreamExt};
use shared_stream::Share;

let shared = stream::iter(1..=3).shared();
assert_eq!(shared.clone().take(1).collect::<Vec<_>>().await, [1]);
assert_eq!(shared.clone().skip(1).take(1).collect::<Vec<_>>().await, [2]);
assert_eq!(shared.collect::<Vec<_>>().await, [1, 2, 3]);
# });

Dependencies

~79KB