Struct ReaderStream

struct ReaderStream<R> { ... }

Convert an AsyncRead into a Stream of byte chunks.

This stream is fused. It performs the inverse operation of StreamReader.

Example

# #[tokio::main]
# async fn main() -> std::io::Result<()> {
use tokio_stream::StreamExt;
use tokio_util::io::ReaderStream;

// Create a stream of data.
let data = b"hello, world!";
let mut stream = ReaderStream::new(&data[..]);

// Read all of the chunks into a vector.
let mut stream_contents = Vec::new();
while let Some(chunk) = stream.next().await {
   stream_contents.extend_from_slice(&chunk?);
}

// Once the chunks are concatenated, we should have the
// original data.
assert_eq!(stream_contents, data);
# Ok(())
# }

Implementations

impl<R: AsyncRead> ReaderStream<R>

fn new(reader: R) -> Self

Convert an AsyncRead into a Stream with item type Result<Bytes, std::io::Error>.

fn with_capacity(reader: R, capacity: usize) -> Self

Convert an AsyncRead into a Stream with item type Result<Bytes, std::io::Error>, with a specific read buffer initial capacity.

impl<'__pin, R> Unpin for ReaderStream<R>

impl<R> Freeze for ReaderStream<R>

impl<R> RefUnwindSafe for ReaderStream<R>

impl<R> Send for ReaderStream<R>

impl<R> Sync for ReaderStream<R>

impl<R> UnsafeUnpin for ReaderStream<R>

impl<R> UnwindSafe for ReaderStream<R>

impl<R: $crate::fmt::Debug> Debug for ReaderStream<R>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<R: AsyncRead> Stream for ReaderStream<R>

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<<Self as >::Item>>

impl<S, T, E> TryStream for ReaderStream<R>

fn try_poll_next(self: Pin<&mut S>, cx: &mut Context<'_>) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

impl<T> Any for ReaderStream<R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ReaderStream<R>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ReaderStream<R>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for ReaderStream<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for ReaderStream<R>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for ReaderStream<R>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for ReaderStream<R>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>