Function tokio::io::reader_stream [−][src]
pub fn reader_stream<R>(reader: R) -> ReaderStream<R> where
R: AsyncRead,
Convert an AsyncRead
implementor into a
Stream
of Result<Bytes
, std::io::Error>.
Example
use tokio::stream::StreamExt; let data: &[u8] = b"hello, world!"; let mut stream = tokio::io::reader_stream(data); let mut stream_contents = Vec::new(); while let Some(chunk) = stream.next().await { stream_contents.extend_from_slice(chunk?.as_ref()); } assert_eq!(stream_contents, data);