1use futures::{stream::BoxStream, Stream};
2use std::{
3 pin::Pin,
4 task::{Context, Poll},
5};
6
7pub struct BoxedStream<'a, T>(BoxStream<'a, T>);
9
10impl<'a, T> BoxedStream<'a, T> {
11 pub fn from_stream<S>(stream: S) -> Self
12 where
13 S: Stream<Item = T> + Send + 'a,
14 {
15 Self(Box::pin(stream))
16 }
17}
18
19impl<T> Stream for BoxedStream<'_, T> {
20 type Item = T;
21
22 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
23 self.0.as_mut().poll_next(cx)
24 }
25}