clone_stream/
lib.rs

1mod bridge;
2mod clone;
3
4use bridge::Bridge;
5pub use clone::CloneStream;
6use futures::Stream;
7
8impl<BaseStream> From<BaseStream> for CloneStream<BaseStream>
9where
10    BaseStream: Stream<Item: Clone>,
11{
12    /// Forks the stream into a new stream that can be cloned.
13    fn from(base_stream: BaseStream) -> CloneStream<BaseStream> {
14        CloneStream::from(Bridge::new(base_stream))
15    }
16}
17
18/// A trait that turns a `Stream` with cloneable `Item`s into a cloneable stream
19/// that yields items of the same original item type.
20pub trait ForkStream: Stream<Item: Clone> + Sized {
21    /// Forks the stream into a new stream that can be cloned.
22    fn fork(self) -> CloneStream<Self> {
23        CloneStream::from(Bridge::new(self))
24    }
25}
26
27impl<BaseStream> ForkStream for BaseStream where BaseStream: Stream<Item: Clone> {}