async_std/stream/stream/
cloned.rs1use crate::stream::Stream;
2use crate::task::{Context, Poll};
3use pin_project_lite::pin_project;
4use core::pin::Pin;
5
6pin_project! {
7 #[derive(Debug)]
9 pub struct Cloned<S> {
10 #[pin]
11 stream: S,
12 }
13}
14
15impl<S> Cloned<S> {
16 pub(super) fn new(stream: S) -> Self {
17 Self { stream }
18 }
19}
20
21impl<'a, S, T: 'a> Stream for Cloned<S>
22where
23 S: Stream<Item = &'a T>,
24 T: Clone,
25{
26 type Item = T;
27
28 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
29 let this = self.project();
30 let next = futures_core::ready!(this.stream.poll_next(cx));
31 Poll::Ready(next.cloned())
32 }
33}