1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! [`futures_core::Stream`] integration.

use futures_util::StreamExt;

/// A [`futures_core::Stream`] reader.
///
/// Allows reading any [`futures_core::Stream`] that
/// returns [`Result<T, E>`]s where `T` implements [`bytes::Buf`].
#[derive(Debug)]
pub struct Reader<T>(pub T);

#[cfg_attr(feature = "async-trait", async_trait::async_trait)]
impl<Stream, Data, Error> crate::Reader for Reader<Stream>
where
    Data: bytes::Buf,
    Stream: futures_core::Stream<Item = Result<Data, Error>> + Unpin,
{
    type Data<'data> = Data;
    type Error = Error;

    async fn next(&mut self) -> Option<Result<Self::Data<'_>, Self::Error>> {
        self.0.next().await
    }
}