diff --git a/tokio-stream/src/stream_ext.rs b/tokio-stream/src/stream_ext.rs index 7e915d990..fe5898692 100644 --- a/tokio-stream/src/stream_ext.rs +++ b/tokio-stream/src/stream_ext.rs @@ -916,7 +916,7 @@ pub trait StreamExt: Stream { /// assert_eq!(Err("no"), values); /// # } /// ``` - fn collect(self) -> Collect + fn collect(self) -> Collect where T: FromStream, Self: Sized, diff --git a/tokio-stream/src/stream_ext/collect.rs b/tokio-stream/src/stream_ext/collect.rs index eb9e2197f..8140f0b4e 100644 --- a/tokio-stream/src/stream_ext/collect.rs +++ b/tokio-stream/src/stream_ext/collect.rs @@ -1,7 +1,7 @@ use crate::Stream; use core::future::Future; -use core::marker::PhantomPinned; +use core::marker::{PhantomData, PhantomPinned}; use core::mem; use core::pin::Pin; use core::task::{ready, Context, Poll}; @@ -12,14 +12,12 @@ pin_project! { /// Future returned by the [`collect`](super::StreamExt::collect) method. #[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] - pub struct Collect - where - T: Stream, - U: FromStream, + pub struct Collect { #[pin] stream: T, - collection: U::InternalCollection, + collection: C, + _output: PhantomData, // Make this future `!Unpin` for compatibility with async trait methods. #[pin] _pin: PhantomPinned, @@ -38,24 +36,25 @@ pin_project! { /// enhancements to the Rust language. pub trait FromStream: sealed::FromStreamPriv {} -impl Collect +impl Collect where T: Stream, U: FromStream, { - pub(super) fn new(stream: T) -> Collect { + pub(super) fn new(stream: T) -> Collect { let (lower, upper) = stream.size_hint(); let collection = U::initialize(sealed::Internal, lower, upper); Collect { stream, collection, + _output: PhantomData, _pin: PhantomPinned, } } } -impl Future for Collect +impl Future for Collect where T: Stream, U: FromStream,