forked_stream

Crates.ioforked_stream
lib.rsforked_stream
version0.1.2
created_at2025-04-02 23:10:06.926928+00
updated_at2025-04-17 14:31:56.679454+00
descriptionConvert any Stream with cloneable items into a cloneable stream.
homepage
repositoryhttps://github.com/wvhulle/forked_stream
max_upload_size
id1617398
size43,699
Willem Vanhulle (wvhulle)

documentation

README

Forkable streams

This Rust library allows you to convert non-cloneable streams into cloneable streams. The only requirement is that the item type of the base-stream is cloneable. The streams are supposed to be Rust types implementing the Stream trait from the common futures crate.

Installation

Make sure you have installed rustup, which installs cargo. Inside an existing cargo project:

cargo add forked_stream futures

If you would like to install the latest git version instead of the release on crates.io:

cargo add --git https://github.com/wvhulle/forked_stream

Usage

Import the trait ForkStream from this crate and call fork on your un-cloneable Stream:

use futures::{FutureExt, StreamExt, stream};
use forked_stream::ForkStream;

let uncloneable_stream = stream::iter(0..10);
let cloneable_stream = uncloneable_stream.fork();
let mut cloned_stream = cloneable_stream.clone();

Contributing

You can run the tests with:

cargo test

Author remarks

This small project was an exercise for me making streams forkable without spawning tasks. This is my first time storing and managing Waker objects. Sorry for any mistakes.

There are a few alternative solutions on crates.io.

Commit count: 113

cargo fmt