clone-stream 0.1.7

Convert any Stream with cloneable items into a cloneable stream.
Documentation

Rust library clone-stream

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 clone-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/clone-stream

Usage

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

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

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

How does it work?

This small project was an exercise for me making streams implement Clone without spawning tasks.

See my blog for more technical information.