forked from mirror/async-std
Add Stream cloned
parent
fa91d7f856
commit
4942dc7f9f
@ -0,0 +1,33 @@
|
|||||||
|
use crate::stream::Stream;
|
||||||
|
use crate::task::{Context, Poll};
|
||||||
|
use pin_project_lite::pin_project;
|
||||||
|
use std::pin::Pin;
|
||||||
|
|
||||||
|
pin_project! {
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(missing_debug_implementations)]
|
||||||
|
pub struct Cloned<S> {
|
||||||
|
#[pin]
|
||||||
|
stream: S,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S> Cloned<S> {
|
||||||
|
pub(super) fn new(stream: S) -> Self {
|
||||||
|
Self { stream }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, S, T: 'a> Stream for Cloned<S>
|
||||||
|
where
|
||||||
|
S: Stream<Item = &'a T>,
|
||||||
|
T: Clone,
|
||||||
|
{
|
||||||
|
type Item = T;
|
||||||
|
|
||||||
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
|
let this = self.project();
|
||||||
|
let next = futures_core::ready!(this.stream.poll_next(cx));
|
||||||
|
Poll::Ready(next.cloned())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue