Move stream items into tokio-stream (#3277)

This change removes all references to `Stream` from
within the `tokio` crate and moves them into a new
`tokio-stream` crate. Most types have had their
`impl Stream` removed as well in-favor of their
inherent methods.

Closes #2870
This commit is contained in:
Lucio Franco
2020-12-15 20:24:38 -08:00
committed by GitHub
parent fcce78b33a
commit 8efa62013b
101 changed files with 710 additions and 577 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ pub trait Decoder {
/// calling `split` on the [`Framed`] returned by this method, which will
/// break them into separate objects, allowing them to interact more easily.
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`Sink`]: futures_sink::Sink
/// [`Framed`]: crate::codec::Framed
fn framed<T: AsyncRead + AsyncWrite + Sized>(self, io: T) -> Framed<T, Self>
+6 -8
View File
@@ -2,10 +2,8 @@ use crate::codec::decoder::Decoder;
use crate::codec::encoder::Encoder;
use crate::codec::framed_impl::{FramedImpl, RWFrames, ReadFrame, WriteFrame};
use tokio::{
io::{AsyncRead, AsyncWrite},
stream::Stream,
};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_stream::Stream;
use bytes::BytesMut;
use futures_sink::Sink;
@@ -22,7 +20,7 @@ pin_project! {
/// You can create a `Framed` instance by using the [`Decoder::framed`] adapter, or
/// by using the `new` function seen below.
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`Sink`]: futures_sink::Sink
/// [`AsyncRead`]: tokio::io::AsyncRead
/// [`Decoder::framed`]: crate::codec::Decoder::framed()
@@ -54,7 +52,7 @@ where
/// calling [`split`] on the `Framed` returned by this method, which will
/// break them into separate objects, allowing them to interact more easily.
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`Sink`]: futures_sink::Sink
/// [`Decode`]: crate::codec::Decoder
/// [`Encoder`]: crate::codec::Encoder
@@ -88,7 +86,7 @@ where
/// calling [`split`] on the `Framed` returned by this method, which will
/// break them into separate objects, allowing them to interact more easily.
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`Sink`]: futures_sink::Sink
/// [`Decode`]: crate::codec::Decoder
/// [`Encoder`]: crate::codec::Encoder
@@ -133,7 +131,7 @@ impl<T, U> Framed<T, U> {
/// calling [`split`] on the `Framed` returned by this method, which will
/// break them into separate objects, allowing them to interact more easily.
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`Sink`]: futures_sink::Sink
/// [`Decoder`]: crate::codec::Decoder
/// [`Encoder`]: crate::codec::Encoder
+2 -4
View File
@@ -1,10 +1,8 @@
use crate::codec::decoder::Decoder;
use crate::codec::encoder::Encoder;
use tokio::{
io::{AsyncRead, AsyncWrite},
stream::Stream,
};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_stream::Stream;
use bytes::BytesMut;
use futures_core::ready;
+3 -2
View File
@@ -1,7 +1,8 @@
use crate::codec::framed_impl::{FramedImpl, ReadFrame};
use crate::codec::Decoder;
use tokio::{io::AsyncRead, stream::Stream};
use tokio::io::AsyncRead;
use tokio_stream::Stream;
use bytes::BytesMut;
use futures_sink::Sink;
@@ -13,7 +14,7 @@ use std::task::{Context, Poll};
pin_project! {
/// A [`Stream`] of messages decoded from an [`AsyncRead`].
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`AsyncRead`]: tokio::io::AsyncRead
pub struct FramedRead<T, D> {
#[pin]
+2 -1
View File
@@ -1,7 +1,8 @@
use crate::codec::encoder::Encoder;
use crate::codec::framed_impl::{FramedImpl, WriteFrame};
use tokio::{io::AsyncWrite, stream::Stream};
use tokio::io::AsyncWrite;
use tokio_stream::Stream;
use futures_sink::Sink;
use pin_project_lite::pin_project;
+1 -1
View File
@@ -11,7 +11,7 @@
//!
//! [`AsyncRead`]: tokio::io::AsyncRead
//! [`AsyncWrite`]: tokio::io::AsyncWrite
//! [`Stream`]: tokio::stream::Stream
//! [`Stream`]: tokio_stream::Stream
//! [`Sink`]: futures_sink::Sink
mod bytes_codec;
+2 -4
View File
@@ -167,10 +167,8 @@ where
#[cfg(test)]
mod tests {
use super::*;
use tokio::{
io::{repeat, AsyncReadExt, Repeat},
stream::{once, Once, StreamExt},
};
use tokio::io::{repeat, AsyncReadExt, Repeat};
use tokio_stream::{once, Once, StreamExt};
#[tokio::test]
async fn either_is_stream() {
+1 -1
View File
@@ -13,7 +13,7 @@ use tokio::io::AsyncRead;
///
/// ```
/// use bytes::{Bytes, BytesMut};
/// use tokio::stream;
/// use tokio_stream as stream;
/// use tokio::io::Result;
/// use tokio_util::io::{StreamReader, read_buf};
/// # #[tokio::main]
+3 -3
View File
@@ -18,7 +18,7 @@ pin_project! {
/// ```
/// # #[tokio::main]
/// # async fn main() -> std::io::Result<()> {
/// use tokio::stream::StreamExt;
/// use tokio_stream::StreamExt;
/// use tokio_util::io::ReaderStream;
///
/// // Create a stream of data.
@@ -40,7 +40,7 @@ pin_project! {
///
/// [`AsyncRead`]: tokio::io::AsyncRead
/// [`StreamReader`]: crate::io::StreamReader
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
#[derive(Debug)]
pub struct ReaderStream<R> {
// Reader itself.
@@ -58,7 +58,7 @@ impl<R: AsyncRead> ReaderStream<R> {
/// `Result<Bytes, std::io::Error>`.
///
/// [`AsyncRead`]: tokio::io::AsyncRead
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
pub fn new(reader: R) -> Self {
ReaderStream {
reader: Some(reader),
+2 -2
View File
@@ -21,7 +21,7 @@ pin_project! {
/// # async fn main() -> std::io::Result<()> {
///
/// // Create a stream from an iterator.
/// let stream = tokio::stream::iter(vec![
/// let stream = tokio_stream::iter(vec![
/// Result::Ok(Bytes::from_static(&[0, 1, 2, 3])),
/// Result::Ok(Bytes::from_static(&[4, 5, 6, 7])),
/// Result::Ok(Bytes::from_static(&[8, 9, 10, 11])),
@@ -51,7 +51,7 @@ pin_project! {
/// ```
///
/// [`AsyncRead`]: tokio::io::AsyncRead
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`ReaderStream`]: crate::io::ReaderStream
#[derive(Debug)]
pub struct StreamReader<S, B> {
+1 -1
View File
@@ -72,7 +72,7 @@ mod util {
///
/// ```
/// use bytes::{Bytes, BytesMut};
/// use tokio::stream;
/// use tokio_stream as stream;
/// use tokio::io::Result;
/// use tokio_util::io::{StreamReader, poll_read_buf};
/// use futures::future::poll_fn;
+3 -2
View File
@@ -1,6 +1,7 @@
use crate::codec::{Decoder, Encoder};
use tokio::{io::ReadBuf, net::UdpSocket, stream::Stream};
use tokio::{io::ReadBuf, net::UdpSocket};
use tokio_stream::Stream;
use bytes::{BufMut, BytesMut};
use futures_core::ready;
@@ -27,7 +28,7 @@ use std::{io, mem::MaybeUninit};
/// calling [`split`] on the `UdpFramed` returned by this method, which will break
/// them into separate objects, allowing them to interact more easily.
///
/// [`Stream`]: tokio::stream::Stream
/// [`Stream`]: tokio_stream::Stream
/// [`Sink`]: futures_sink::Sink
/// [`split`]: https://docs.rs/futures/0.3/futures/stream/trait.StreamExt.html#method.split
#[must_use = "sinks do nothing unless polled"]