Repository: tokio-rs/tokio
File: tokio-util/src/io/stream_reader.rs (Rust)

Code before:
    ///     Result::Err("Something bad happened!")
    /// ]);
    ///
    /// // Use StreamExt to map the stream and error to a std::io::Error
    /// let stream = stream.map(|result| result.map_err(|err| {
    ///     std::io::Error::new(std::io::ErrorKind::Other, err)
    /// }));
    ///
    /// // Convert it to an AsyncRead.
    /// let mut read = StreamReader::new(stream);
    ///
    /// // Read five bytes from the stream.
    /// let mut buf = [0; 5];
    /// read.read_exact(&mut buf).await?;
    /// assert_eq!(buf, [0, 1, 2, 3, 4]);
    ///
    /// // Read the rest of the current chunk.
    /// assert_eq!(read.read(&mut buf).await?, 3);
    /// assert_eq!(&buf[..3], [5, 6, 7]);
    ///
    /// // Reading the next chunk will produce an error
    /// let error = read.read(&mut buf).await.unwrap_err();
    /// assert_eq!(error.kind(), std::io::ErrorKind::Other);
    /// assert_eq!(error.into_inner().unwrap().to_string(), "Something bad happened!");
    ///
    ///
    /// // We have now reached the end.
    /// assert_eq!(read.read(&mut buf).await?, 0);
    ///
    /// # Ok(())
    /// # }
    /// ```
    ///
    /// [`AsyncRead`]: tokio::io::AsyncRead
    /// [`Stream`]: futures_core::Stream
    /// [`ReaderStream`]: crate::io::ReaderStream
    /// [`StreamExt`]: tokio_stream::StreamExt
    #[derive(Debug)]
    pub struct StreamReader<S, B> {
        #[pin]
        inner: S,
        chunk: Option<B>,
    }
}

impl<S, B, E> StreamReader<S, B>
where
    S: Stream<Item = Result<B, E>>,
    B: Buf,
    E: Into<std::io::Error>,
{

Review comment (suggestion):
Oops, this was the one I intended to remove.
```suggestion
    ///
```

Code after:
    ///     Result::Err("Something bad happened!")
    /// ]);
    ///
    /// // Use StreamExt to map the stream and error to a std::io::Error
    /// let stream = stream.map(|result| result.map_err(|err| {
    ///     std::io::Error::new(std::io::ErrorKind::Other, err)
    /// }));
    ///
    /// // Convert it to an AsyncRead.
    /// let mut read = StreamReader::new(stream);
    ///
    /// // Read five bytes from the stream.
    /// let mut buf = [0; 5];
    /// read.read_exact(&mut buf).await?;
    /// assert_eq!(buf, [0, 1, 2, 3, 4]);
    ///
    /// // Read the rest of the current chunk.
    /// assert_eq!(read.read(&mut buf).await?, 3);
    /// assert_eq!(&buf[..3], [5, 6, 7]);
    ///
    /// // Reading the next chunk will produce an error
    /// let error = read.read(&mut buf).await.unwrap_err();
    /// assert_eq!(error.kind(), std::io::ErrorKind::Other);
    /// assert_eq!(error.into_inner().unwrap().to_string(), "Something bad happened!");
    ///
    /// // We have now reached the end.
    /// assert_eq!(read.read(&mut buf).await?, 0);
    ///
    /// # Ok(())
    /// # }
    /// ```
    ///
    /// [`AsyncRead`]: tokio::io::AsyncRead
    /// [`Stream`]: futures_core::Stream
    /// [`ReaderStream`]: crate::io::ReaderStream
    /// [`StreamExt`]: tokio_stream::StreamExt
    #[derive(Debug)]
    pub struct StreamReader<S, B> {
        #[pin]
        inner: S,
        chunk: Option<B>,
    }
}

impl<S, B, E> StreamReader<S, B>
where
    S: Stream<Item = Result<B, E>>,
    B: Buf,
    E: Into<std::io::Error>,
{
    /// Convert a stream of byte chunks into an [`AsyncRead`](tokio::io::AsyncRead).