diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index 6f3d4b0233..b4c7532d4f 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -46,7 +46,7 @@ memchr = { version = "2.2", optional = true } futures_01 = { version = "0.1.25", optional = true, package = "futures" } tokio-io = { version = "0.1.9", optional = true } pin-utils = "0.1.0" -pin-project = "1.0.1" +pin-project-lite = "0.2" [dev-dependencies] futures = { path = "../futures", version = "0.3.8", features = ["async-await", "thread-pool"] } diff --git a/futures-util/src/future/abortable.rs b/futures-util/src/future/abortable.rs index 7b92a767fd..1fc75b08fc 100644 --- a/futures-util/src/future/abortable.rs +++ b/futures-util/src/future/abortable.rs @@ -5,16 +5,17 @@ use core::fmt; use core::pin::Pin; use core::sync::atomic::{AtomicBool, Ordering}; use alloc::sync::Arc; -use pin_project::pin_project; - -/// A future which can be remotely short-circuited using an `AbortHandle`. -#[pin_project] -#[derive(Debug, Clone)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Abortable { - #[pin] - future: Fut, - inner: Arc, +use pin_project_lite::pin_project; + +pin_project! { + /// A future which can be remotely short-circuited using an `AbortHandle`. + #[derive(Debug, Clone)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Abortable { + #[pin] + future: Fut, + inner: Arc, + } } impl Abortable where Fut: Future { diff --git a/futures-util/src/future/either.rs b/futures-util/src/future/either.rs index aa17fa7705..ee784cd047 100644 --- a/futures-util/src/future/either.rs +++ b/futures-util/src/future/either.rs @@ -4,17 +4,26 @@ use futures_core::future::{FusedFuture, Future}; use futures_core::stream::{FusedStream, Stream}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; /// Combines two different futures, streams, or sinks having the same associated types into a single /// type. -#[pin_project(project = EitherProj)] #[derive(Debug, Clone)] pub enum Either { /// First branch of the type - Left(#[pin] A), + Left(A), /// Second branch of the type - Right(#[pin] B), + Right(B), +} + +impl Either { + fn project(self: Pin<&mut Self>) -> Either, Pin<&mut B>> { + unsafe { + match self.get_unchecked_mut() { + Either::Left(a) => Either::Left(Pin::new_unchecked(a)), + Either::Right(b) => Either::Right(Pin::new_unchecked(b)), + } + } + } } impl Either<(T, A), (T, B)> { @@ -60,8 +69,8 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match self.project() { - EitherProj::Left(x) => x.poll(cx), - EitherProj::Right(x) => x.poll(cx), + Either::Left(x) => x.poll(cx), + Either::Right(x) => x.poll(cx), } } } @@ -88,8 +97,8 @@ where fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_next(cx), - EitherProj::Right(x) => x.poll_next(cx), + Either::Left(x) => x.poll_next(cx), + Either::Right(x) => x.poll_next(cx), } } } @@ -117,29 +126,29 @@ where fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_ready(cx), - EitherProj::Right(x) => x.poll_ready(cx), + Either::Left(x) => x.poll_ready(cx), + Either::Right(x) => x.poll_ready(cx), } } fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> { match self.project() { - EitherProj::Left(x) => x.start_send(item), - EitherProj::Right(x) => x.start_send(item), + Either::Left(x) => x.start_send(item), + Either::Right(x) => x.start_send(item), } } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_flush(cx), - EitherProj::Right(x) => x.poll_flush(cx), + Either::Left(x) => x.poll_flush(cx), + Either::Right(x) => x.poll_flush(cx), } } fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_close(cx), - EitherProj::Right(x) => x.poll_close(cx), + Either::Left(x) => x.poll_close(cx), + Either::Right(x) => x.poll_close(cx), } } } @@ -176,8 +185,8 @@ mod if_std { buf: &mut [u8], ) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_read(cx, buf), - EitherProj::Right(x) => x.poll_read(cx, buf), + Either::Left(x) => x.poll_read(cx, buf), + Either::Right(x) => x.poll_read(cx, buf), } } @@ -187,8 +196,8 @@ mod if_std { bufs: &mut [IoSliceMut<'_>], ) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_read_vectored(cx, bufs), - EitherProj::Right(x) => x.poll_read_vectored(cx, bufs), + Either::Left(x) => x.poll_read_vectored(cx, bufs), + Either::Right(x) => x.poll_read_vectored(cx, bufs), } } } @@ -204,8 +213,8 @@ mod if_std { buf: &[u8], ) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_write(cx, buf), - EitherProj::Right(x) => x.poll_write(cx, buf), + Either::Left(x) => x.poll_write(cx, buf), + Either::Right(x) => x.poll_write(cx, buf), } } @@ -215,22 +224,22 @@ mod if_std { bufs: &[IoSlice<'_>], ) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_write_vectored(cx, bufs), - EitherProj::Right(x) => x.poll_write_vectored(cx, bufs), + Either::Left(x) => x.poll_write_vectored(cx, bufs), + Either::Right(x) => x.poll_write_vectored(cx, bufs), } } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_flush(cx), - EitherProj::Right(x) => x.poll_flush(cx), + Either::Left(x) => x.poll_flush(cx), + Either::Right(x) => x.poll_flush(cx), } } fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_close(cx), - EitherProj::Right(x) => x.poll_close(cx), + Either::Left(x) => x.poll_close(cx), + Either::Right(x) => x.poll_close(cx), } } } @@ -246,8 +255,8 @@ mod if_std { pos: SeekFrom, ) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_seek(cx, pos), - EitherProj::Right(x) => x.poll_seek(cx, pos), + Either::Left(x) => x.poll_seek(cx, pos), + Either::Right(x) => x.poll_seek(cx, pos), } } } @@ -259,15 +268,15 @@ mod if_std { { fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - EitherProj::Left(x) => x.poll_fill_buf(cx), - EitherProj::Right(x) => x.poll_fill_buf(cx), + Either::Left(x) => x.poll_fill_buf(cx), + Either::Right(x) => x.poll_fill_buf(cx), } } fn consume(self: Pin<&mut Self>, amt: usize) { match self.project() { - EitherProj::Left(x) => x.consume(amt), - EitherProj::Right(x) => x.consume(amt), + Either::Left(x) => x.consume(amt), + Either::Right(x) => x.consume(amt), } } } diff --git a/futures-util/src/future/future/catch_unwind.rs b/futures-util/src/future/future/catch_unwind.rs index 123f5e3517..3f16577788 100644 --- a/futures-util/src/future/future/catch_unwind.rs +++ b/futures-util/src/future/future/catch_unwind.rs @@ -4,17 +4,21 @@ use std::panic::{catch_unwind, UnwindSafe, AssertUnwindSafe}; use futures_core::future::Future; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`catch_unwind`](super::FutureExt::catch_unwind) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct CatchUnwind(#[pin] Fut); +pin_project! { + /// Future for the [`catch_unwind`](super::FutureExt::catch_unwind) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct CatchUnwind { + #[pin] + future: Fut, + } +} impl CatchUnwind where Fut: Future + UnwindSafe { pub(super) fn new(future: Fut) -> Self { - Self(future) + Self { future } } } @@ -24,7 +28,7 @@ impl Future for CatchUnwind type Output = Result>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let f = self.project().0; + let f = self.project().future; catch_unwind(AssertUnwindSafe(|| f.poll(cx)))?.map(Ok) } } diff --git a/futures-util/src/future/future/flatten.rs b/futures-util/src/future/future/flatten.rs index 931fd0b99d..0c48a4f1d4 100644 --- a/futures-util/src/future/future/flatten.rs +++ b/futures-util/src/future/future/flatten.rs @@ -5,19 +5,21 @@ use futures_core::stream::{FusedStream, Stream}; #[cfg(feature = "sink")] use futures_sink::Sink; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -#[pin_project(project = FlattenProj)] -#[derive(Debug)] -pub enum Flatten { - First(#[pin] Fut1), - Second(#[pin] Fut2), - Empty, +pin_project! { + #[project = FlattenProj] + #[derive(Debug)] + pub enum Flatten { + First { #[pin] f: Fut1 }, + Second { #[pin] f: Fut2 }, + Empty, + } } impl Flatten { pub(crate) fn new(future: Fut1) -> Self { - Self::First(future) + Self::First { f: future } } } @@ -42,11 +44,11 @@ impl Future for Flatten fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Poll::Ready(loop { match self.as_mut().project() { - FlattenProj::First(f) => { + FlattenProj::First { f } => { let f = ready!(f.poll(cx)); - self.set(Self::Second(f)); + self.set(Self::Second { f }); }, - FlattenProj::Second(f) => { + FlattenProj::Second { f } => { let output = ready!(f.poll(cx)); self.set(Self::Empty); break output; @@ -78,11 +80,11 @@ impl Stream for Flatten fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Poll::Ready(loop { match self.as_mut().project() { - FlattenProj::First(f) => { + FlattenProj::First { f } => { let f = ready!(f.poll(cx)); - self.set(Self::Second(f)); + self.set(Self::Second { f }); }, - FlattenProj::Second(f) => { + FlattenProj::Second { f } => { let output = ready!(f.poll_next(cx)); if output.is_none() { self.set(Self::Empty); @@ -110,11 +112,11 @@ where ) -> Poll> { Poll::Ready(loop { match self.as_mut().project() { - FlattenProj::First(f) => { + FlattenProj::First { f } => { let f = ready!(f.poll(cx)); - self.set(Self::Second(f)); + self.set(Self::Second { f }); }, - FlattenProj::Second(f) => { + FlattenProj::Second { f } => { break ready!(f.poll_ready(cx)); }, FlattenProj::Empty => panic!("poll_ready called after eof"), @@ -124,16 +126,16 @@ where fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> { match self.project() { - FlattenProj::First(_) => panic!("poll_ready not called first"), - FlattenProj::Second(f) => f.start_send(item), + FlattenProj::First { .. } => panic!("poll_ready not called first"), + FlattenProj::Second { f } => f.start_send(item), FlattenProj::Empty => panic!("start_send called after eof"), } } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - FlattenProj::First(_) => Poll::Ready(Ok(())), - FlattenProj::Second(f) => f.poll_flush(cx), + FlattenProj::First { .. } => Poll::Ready(Ok(())), + FlattenProj::Second { f } => f.poll_flush(cx), FlattenProj::Empty => panic!("poll_flush called after eof"), } } @@ -143,7 +145,7 @@ where cx: &mut Context<'_>, ) -> Poll> { let res = match self.as_mut().project() { - FlattenProj::Second(f) => f.poll_close(cx), + FlattenProj::Second { f } => f.poll_close(cx), _ => Poll::Ready(Ok(())), }; if res.is_ready() { diff --git a/futures-util/src/future/future/fuse.rs b/futures-util/src/future/future/fuse.rs index 6f8a3efddd..f4284ba373 100644 --- a/futures-util/src/future/future/fuse.rs +++ b/futures-util/src/future/future/fuse.rs @@ -2,17 +2,21 @@ use core::pin::Pin; use futures_core::future::{Future, FusedFuture}; use futures_core::ready; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`fuse`](super::FutureExt::fuse) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Fuse(#[pin] Option); +pin_project! { + /// Future for the [`fuse`](super::FutureExt::fuse) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Fuse { + #[pin] + inner: Option, + } +} impl Fuse { pub(super) fn new(f: Fut) -> Self { - Self(Some(f)) + Self { inner: Some(f) } } } @@ -63,13 +67,13 @@ impl Fuse { /// # }); /// ``` pub fn terminated() -> Self { - Self(None) + Self { inner: None } } } impl FusedFuture for Fuse { fn is_terminated(&self) -> bool { - self.0.is_none() + self.inner.is_none() } } @@ -77,10 +81,10 @@ impl Future for Fuse { type Output = Fut::Output; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - Poll::Ready(match self.as_mut().project().0.as_pin_mut() { + Poll::Ready(match self.as_mut().project().inner.as_pin_mut() { Some(fut) => { let output = ready!(fut.poll(cx)); - self.project().0.set(None); + self.project().inner.set(None); output }, None => return Poll::Pending, diff --git a/futures-util/src/future/future/map.rs b/futures-util/src/future/future/map.rs index ad8bb77b9b..b692c0a2ab 100644 --- a/futures-util/src/future/future/map.rs +++ b/futures-util/src/future/future/map.rs @@ -2,27 +2,29 @@ use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use crate::fns::FnOnce1; -/// Internal Map future -#[pin_project(project = MapProj, project_replace = MapProjOwn)] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub enum Map { - Incomplete { - #[pin] - future: Fut, - f: F, - }, - Complete, +pin_project! { + /// Internal Map future + #[project = MapProj] + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub enum Map { + Incomplete { + #[pin] + future: Fut, + f: Option, + }, + Complete, + } } impl Map { /// Creates a new Map. pub(crate) fn new(future: Fut, f: F) -> Self { - Self::Incomplete { future, f } + Self::Incomplete { future, f: Some(f) } } } @@ -46,12 +48,11 @@ impl Future for Map fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match self.as_mut().project() { - MapProj::Incomplete { future, .. } => { + MapProj::Incomplete { future, f } => { let output = ready!(future.poll(cx)); - match self.project_replace(Self::Complete) { - MapProjOwn::Incomplete { f, .. } => Poll::Ready(f.call_once(output)), - MapProjOwn::Complete => unreachable!(), - } + let f = f.take().unwrap(); + self.set(Self::Complete); + Poll::Ready(f.call_once(output)) }, MapProj::Complete => panic!("Map must not be polled after it returned `Poll::Ready`"), } diff --git a/futures-util/src/future/future/remote_handle.rs b/futures-util/src/future/future/remote_handle.rs index bc29d82a29..0d33ea5189 100644 --- a/futures-util/src/future/future/remote_handle.rs +++ b/futures-util/src/future/future/remote_handle.rs @@ -17,7 +17,7 @@ use { }, thread, }, - pin_project::pin_project, + pin_project_lite::pin_project, }; /// The handle to a remote future returned by @@ -70,16 +70,17 @@ impl Future for RemoteHandle { type SendMsg = Result<::Output, Box<(dyn Any + Send + 'static)>>; -/// A future which sends its output to the corresponding `RemoteHandle`. -/// Created by [`remote_handle`](crate::future::FutureExt::remote_handle). -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -#[cfg_attr(docsrs, doc(cfg(feature = "channel")))] -pub struct Remote { - tx: Option>>, - keep_running: Arc, - #[pin] - future: CatchUnwind>, +pin_project! { + /// A future which sends its output to the corresponding `RemoteHandle`. + /// Created by [`remote_handle`](crate::future::FutureExt::remote_handle). + #[must_use = "futures do nothing unless you `.await` or poll them"] + #[cfg_attr(docsrs, doc(cfg(feature = "channel")))] + pub struct Remote { + tx: Option>>, + keep_running: Arc, + #[pin] + future: CatchUnwind>, + } } impl fmt::Debug for Remote { diff --git a/futures-util/src/future/join.rs b/futures-util/src/future/join.rs index 0005b08173..cfe53a72c8 100644 --- a/futures-util/src/future/join.rs +++ b/futures-util/src/future/join.rs @@ -5,7 +5,7 @@ use core::fmt; use core::pin::Pin; use futures_core::future::{Future, FusedFuture}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use super::assert_future; @@ -14,11 +14,12 @@ macro_rules! generate { $(#[$doc:meta])* ($Join:ident, <$($Fut:ident),*>), )*) => ($( - $(#[$doc])* - #[pin_project] - #[must_use = "futures do nothing unless you `.await` or poll them"] - pub struct $Join<$($Fut: Future),*> { - $(#[pin] $Fut: MaybeDone<$Fut>,)* + pin_project! { + $(#[$doc])* + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct $Join<$($Fut: Future),*> { + $(#[pin] $Fut: MaybeDone<$Fut>,)* + } } impl<$($Fut),*> fmt::Debug for $Join<$($Fut),*> diff --git a/futures-util/src/future/maybe_done.rs b/futures-util/src/future/maybe_done.rs index ec9c1d83e4..10b48a22e9 100644 --- a/futures-util/src/future/maybe_done.rs +++ b/futures-util/src/future/maybe_done.rs @@ -1,19 +1,18 @@ //! Definition of the MaybeDone combinator +use core::mem; use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; /// A future that may have completed. /// /// This is created by the [`maybe_done()`] function. -#[pin_project(project = MaybeDoneProj, project_replace = MaybeDoneProjOwn)] #[derive(Debug)] pub enum MaybeDone { /// A not-yet-completed future - Future(#[pin] Fut), + Future(Fut), /// The output of the completed future Done(Fut::Output), /// The empty variant after the result of a [`MaybeDone`] has been @@ -49,9 +48,11 @@ impl MaybeDone { /// has not yet been called. #[inline] pub fn output_mut(self: Pin<&mut Self>) -> Option<&mut Fut::Output> { - match self.project() { - MaybeDoneProj::Done(res) => Some(res), - _ => None, + unsafe { + match self.get_unchecked_mut() { + MaybeDone::Done(res) => Some(res), + _ => None, + } } } @@ -63,9 +64,11 @@ impl MaybeDone { Self::Done(_) => {} Self::Future(_) | Self::Gone => return None, } - match self.project_replace(Self::Gone) { - MaybeDoneProjOwn::Done(output) => Some(output), - _ => unreachable!(), + unsafe { + match mem::replace(self.get_unchecked_mut(), Self::Gone) { + MaybeDone::Done(output) => Some(output), + _ => unreachable!(), + } } } } @@ -83,13 +86,15 @@ impl Future for MaybeDone { type Output = (); fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.as_mut().project() { - MaybeDoneProj::Future(f) => { - let res = ready!(f.poll(cx)); - self.set(Self::Done(res)); + unsafe { + match self.as_mut().get_unchecked_mut() { + MaybeDone::Future(f) => { + let res = ready!(Pin::new_unchecked(f).poll(cx)); + self.set(Self::Done(res)); + } + MaybeDone::Done(_) => {} + MaybeDone::Gone => panic!("MaybeDone polled after value taken"), } - MaybeDoneProj::Done(_) => {} - MaybeDoneProj::Gone => panic!("MaybeDone polled after value taken"), } Poll::Ready(()) } diff --git a/futures-util/src/future/option.rs b/futures-util/src/future/option.rs index b58911264c..85939d6b1a 100644 --- a/futures-util/src/future/option.rs +++ b/futures-util/src/future/option.rs @@ -3,29 +3,33 @@ use core::pin::Pin; use futures_core::future::{Future, FusedFuture}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// A future representing a value which may or may not be present. -/// -/// Created by the [`From`] implementation for [`Option`](std::option::Option). -/// -/// # Examples -/// -/// ``` -/// # futures::executor::block_on(async { -/// use futures::future::OptionFuture; -/// -/// let mut a: OptionFuture<_> = Some(async { 123 }).into(); -/// assert_eq!(a.await, Some(123)); -/// -/// a = None.into(); -/// assert_eq!(a.await, None); -/// # }); -/// ``` -#[pin_project] -#[derive(Debug, Clone)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct OptionFuture(#[pin] Option); +pin_project! { + /// A future representing a value which may or may not be present. + /// + /// Created by the [`From`] implementation for [`Option`](std::option::Option). + /// + /// # Examples + /// + /// ``` + /// # futures::executor::block_on(async { + /// use futures::future::OptionFuture; + /// + /// let mut a: OptionFuture<_> = Some(async { 123 }).into(); + /// assert_eq!(a.await, Some(123)); + /// + /// a = None.into(); + /// assert_eq!(a.await, None); + /// # }); + /// ``` + #[derive(Debug, Clone)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct OptionFuture { + #[pin] + inner: Option, + } +} impl Future for OptionFuture { type Output = Option; @@ -34,7 +38,7 @@ impl Future for OptionFuture { self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll { - match self.project().0.as_pin_mut() { + match self.project().inner.as_pin_mut() { Some(x) => x.poll(cx).map(Some), None => Poll::Ready(None), } @@ -43,7 +47,7 @@ impl Future for OptionFuture { impl FusedFuture for OptionFuture { fn is_terminated(&self) -> bool { - match &self.0 { + match &self.inner { Some(x) => x.is_terminated(), None => true, } @@ -52,6 +56,6 @@ impl FusedFuture for OptionFuture { impl From> for OptionFuture { fn from(option: Option) -> Self { - Self(option) + Self { inner: option } } } diff --git a/futures-util/src/future/try_future/into_future.rs b/futures-util/src/future/try_future/into_future.rs index 5c43bdd4f2..e88d603c0f 100644 --- a/futures-util/src/future/try_future/into_future.rs +++ b/futures-util/src/future/try_future/into_future.rs @@ -1,23 +1,27 @@ use core::pin::Pin; use futures_core::future::{FusedFuture, Future, TryFuture}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`into_future`](super::TryFutureExt::into_future) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct IntoFuture(#[pin] Fut); +pin_project! { + /// Future for the [`into_future`](super::TryFutureExt::into_future) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct IntoFuture { + #[pin] + future: Fut, + } +} impl IntoFuture { #[inline] pub(crate) fn new(future: Fut) -> Self { - Self(future) + Self { future } } } impl FusedFuture for IntoFuture { - fn is_terminated(&self) -> bool { self.0.is_terminated() } + fn is_terminated(&self) -> bool { self.future.is_terminated() } } impl Future for IntoFuture { @@ -28,6 +32,6 @@ impl Future for IntoFuture { self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll { - self.project().0.try_poll(cx) + self.project().future.try_poll(cx) } } diff --git a/futures-util/src/future/try_future/try_flatten.rs b/futures-util/src/future/try_future/try_flatten.rs index 7ebfe1373f..5241b2750d 100644 --- a/futures-util/src/future/try_future/try_flatten.rs +++ b/futures-util/src/future/try_future/try_flatten.rs @@ -5,19 +5,21 @@ use futures_core::stream::{FusedStream, Stream, TryStream}; #[cfg(feature = "sink")] use futures_sink::Sink; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -#[pin_project(project = TryFlattenProj)] -#[derive(Debug)] -pub enum TryFlatten { - First(#[pin] Fut1), - Second(#[pin] Fut2), - Empty, +pin_project! { + #[project = TryFlattenProj] + #[derive(Debug)] + pub enum TryFlatten { + First { #[pin] f: Fut1 }, + Second { #[pin] f: Fut2 }, + Empty, + } } impl TryFlatten { pub(crate) fn new(future: Fut1) -> Self { - Self::First(future) + Self::First { f: future } } } @@ -42,16 +44,16 @@ impl Future for TryFlatten fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Poll::Ready(loop { match self.as_mut().project() { - TryFlattenProj::First(f) => { + TryFlattenProj::First { f } => { match ready!(f.try_poll(cx)) { - Ok(f) => self.set(Self::Second(f)), + Ok(f) => self.set(Self::Second { f }), Err(e) => { self.set(Self::Empty); break Err(e); } } }, - TryFlattenProj::Second(f) => { + TryFlattenProj::Second { f } => { let output = ready!(f.try_poll(cx)); self.set(Self::Empty); break output; @@ -83,16 +85,16 @@ impl Stream for TryFlatten fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Poll::Ready(loop { match self.as_mut().project() { - TryFlattenProj::First(f) => { + TryFlattenProj::First { f } => { match ready!(f.try_poll(cx)) { - Ok(f) => self.set(Self::Second(f)), + Ok(f) => self.set(Self::Second { f }), Err(e) => { self.set(Self::Empty); break Some(Err(e)); } } }, - TryFlattenProj::Second(f) => { + TryFlattenProj::Second { f } => { let output = ready!(f.try_poll_next(cx)); if output.is_none() { self.set(Self::Empty); @@ -120,16 +122,16 @@ where ) -> Poll> { Poll::Ready(loop { match self.as_mut().project() { - TryFlattenProj::First(f) => { + TryFlattenProj::First { f } => { match ready!(f.try_poll(cx)) { - Ok(f) => self.set(Self::Second(f)), + Ok(f) => self.set(Self::Second { f }), Err(e) => { self.set(Self::Empty); break Err(e); } } }, - TryFlattenProj::Second(f) => { + TryFlattenProj::Second { f } => { break ready!(f.poll_ready(cx)); }, TryFlattenProj::Empty => panic!("poll_ready called after eof"), @@ -139,16 +141,16 @@ where fn start_send(self: Pin<&mut Self>, item: Item) -> Result<(), Self::Error> { match self.project() { - TryFlattenProj::First(_) => panic!("poll_ready not called first"), - TryFlattenProj::Second(f) => f.start_send(item), + TryFlattenProj::First { .. } => panic!("poll_ready not called first"), + TryFlattenProj::Second { f } => f.start_send(item), TryFlattenProj::Empty => panic!("start_send called after eof"), } } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { match self.project() { - TryFlattenProj::First(_) => Poll::Ready(Ok(())), - TryFlattenProj::Second(f) => f.poll_flush(cx), + TryFlattenProj::First { .. } => Poll::Ready(Ok(())), + TryFlattenProj::Second { f } => f.poll_flush(cx), TryFlattenProj::Empty => panic!("poll_flush called after eof"), } } @@ -158,7 +160,7 @@ where cx: &mut Context<'_>, ) -> Poll> { let res = match self.as_mut().project() { - TryFlattenProj::Second(f) => f.poll_close(cx), + TryFlattenProj::Second { f } => f.poll_close(cx), _ => Poll::Ready(Ok(())), }; if res.is_ready() { diff --git a/futures-util/src/future/try_future/try_flatten_err.rs b/futures-util/src/future/try_future/try_flatten_err.rs index aa57f587cc..2e67f1104e 100644 --- a/futures-util/src/future/try_future/try_flatten_err.rs +++ b/futures-util/src/future/try_future/try_flatten_err.rs @@ -2,19 +2,21 @@ use core::pin::Pin; use futures_core::future::{FusedFuture, Future, TryFuture}; use futures_core::ready; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -#[pin_project(project = TryFlattenErrProj)] -#[derive(Debug)] -pub enum TryFlattenErr { - First(#[pin] Fut1), - Second(#[pin] Fut2), - Empty, +pin_project! { + #[project = TryFlattenErrProj] + #[derive(Debug)] + pub enum TryFlattenErr { + First { #[pin] f: Fut1 }, + Second { #[pin] f: Fut2 }, + Empty, + } } impl TryFlattenErr { pub(crate) fn new(future: Fut1) -> Self { - Self::First(future) + Self::First { f: future } } } @@ -39,16 +41,16 @@ impl Future for TryFlattenErr fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Poll::Ready(loop { match self.as_mut().project() { - TryFlattenErrProj::First(f) => { + TryFlattenErrProj::First { f } => { match ready!(f.try_poll(cx)) { - Err(f) => self.set(Self::Second(f)), + Err(f) => self.set(Self::Second { f }), Ok(e) => { self.set(Self::Empty); break Ok(e); } } }, - TryFlattenErrProj::Second(f) => { + TryFlattenErrProj::Second { f } => { let output = ready!(f.try_poll(cx)); self.set(Self::Empty); break output; diff --git a/futures-util/src/future/try_join.rs b/futures-util/src/future/try_join.rs index c12dbb139f..25ccdde39c 100644 --- a/futures-util/src/future/try_join.rs +++ b/futures-util/src/future/try_join.rs @@ -5,19 +5,20 @@ use core::fmt; use core::pin::Pin; use futures_core::future::{Future, TryFuture}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; macro_rules! generate { ($( $(#[$doc:meta])* ($Join:ident, ), )*) => ($( - $(#[$doc])* - #[pin_project] - #[must_use = "futures do nothing unless you `.await` or poll them"] - pub struct $Join { - #[pin] Fut1: TryMaybeDone, - $(#[pin] $Fut: TryMaybeDone<$Fut>,)* + pin_project! { + $(#[$doc])* + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct $Join { + #[pin] Fut1: TryMaybeDone, + $(#[pin] $Fut: TryMaybeDone<$Fut>,)* + } } impl fmt::Debug for $Join diff --git a/futures-util/src/future/try_maybe_done.rs b/futures-util/src/future/try_maybe_done.rs index d0797610d1..1c95d22fc8 100644 --- a/futures-util/src/future/try_maybe_done.rs +++ b/futures-util/src/future/try_maybe_done.rs @@ -1,19 +1,18 @@ //! Definition of the TryMaybeDone combinator +use core::mem; use core::pin::Pin; use futures_core::future::{FusedFuture, Future, TryFuture}; use futures_core::ready; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; /// A future that may have completed with an error. /// /// This is created by the [`try_maybe_done()`] function. -#[pin_project(project = TryMaybeDoneProj, project_replace = TryMaybeDoneProjOwn)] #[derive(Debug)] pub enum TryMaybeDone { /// A not-yet-completed future - Future(#[pin] Fut), + Future(Fut), /// The output of the completed future Done(Fut::Ok), /// The empty variant after the result of a [`TryMaybeDone`] has been @@ -34,9 +33,11 @@ impl TryMaybeDone { /// has not yet been called. #[inline] pub fn output_mut(self: Pin<&mut Self>) -> Option<&mut Fut::Ok> { - match self.project() { - TryMaybeDoneProj::Done(res) => Some(res), - _ => None, + unsafe { + match self.get_unchecked_mut() { + TryMaybeDone::Done(res) => Some(res), + _ => None, + } } } @@ -48,9 +49,11 @@ impl TryMaybeDone { Self::Done(_) => {}, Self::Future(_) | Self::Gone => return None, } - match self.project_replace(Self::Gone) { - TryMaybeDoneProjOwn::Done(output) => Some(output), - _ => unreachable!() + unsafe { + match mem::replace(self.get_unchecked_mut(), Self::Gone) { + TryMaybeDone::Done(output) => Some(output), + _ => unreachable!() + } } } } @@ -68,18 +71,20 @@ impl Future for TryMaybeDone { type Output = Result<(), Fut::Error>; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.as_mut().project() { - TryMaybeDoneProj::Future(f) => { - match ready!(f.try_poll(cx)) { - Ok(res) => self.set(Self::Done(res)), - Err(e) => { - self.set(Self::Gone); - return Poll::Ready(Err(e)); + unsafe { + match self.as_mut().get_unchecked_mut() { + TryMaybeDone::Future(f) => { + match ready!(Pin::new_unchecked(f).try_poll(cx)) { + Ok(res) => self.set(Self::Done(res)), + Err(e) => { + self.set(Self::Gone); + return Poll::Ready(Err(e)); + } } - } - }, - TryMaybeDoneProj::Done(_) => {}, - TryMaybeDoneProj::Gone => panic!("TryMaybeDone polled after value taken"), + }, + TryMaybeDone::Done(_) => {}, + TryMaybeDone::Gone => panic!("TryMaybeDone polled after value taken"), + } } Poll::Ready(Ok(())) } diff --git a/futures-util/src/io/buf_reader.rs b/futures-util/src/io/buf_reader.rs index a50e5c149f..270a086cf8 100644 --- a/futures-util/src/io/buf_reader.rs +++ b/futures-util/src/io/buf_reader.rs @@ -3,38 +3,39 @@ use futures_core::task::{Context, Poll}; #[cfg(feature = "read-initializer")] use futures_io::Initializer; use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSliceMut, SeekFrom}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::io::{self, Read}; use std::pin::Pin; use std::{cmp, fmt}; use super::DEFAULT_BUF_SIZE; -/// The `BufReader` struct adds buffering to any reader. -/// -/// It can be excessively inefficient to work directly with a [`AsyncRead`] -/// instance. A `BufReader` performs large, infrequent reads on the underlying -/// [`AsyncRead`] and maintains an in-memory buffer of the results. -/// -/// `BufReader` can improve the speed of programs that make *small* and -/// *repeated* read calls to the same file or network socket. It does not -/// help when reading very large amounts at once, or reading just one or a few -/// times. It also provides no advantage when reading from a source that is -/// already in memory, like a `Vec`. -/// -/// When the `BufReader` is dropped, the contents of its buffer will be -/// discarded. Creating multiple instances of a `BufReader` on the same -/// stream can cause data loss. -/// -/// [`AsyncRead`]: futures_io::AsyncRead -/// -// TODO: Examples -#[pin_project] -pub struct BufReader { - #[pin] - inner: R, - buffer: Box<[u8]>, - pos: usize, - cap: usize, +pin_project! { + /// The `BufReader` struct adds buffering to any reader. + /// + /// It can be excessively inefficient to work directly with a [`AsyncRead`] + /// instance. A `BufReader` performs large, infrequent reads on the underlying + /// [`AsyncRead`] and maintains an in-memory buffer of the results. + /// + /// `BufReader` can improve the speed of programs that make *small* and + /// *repeated* read calls to the same file or network socket. It does not + /// help when reading very large amounts at once, or reading just one or a few + /// times. It also provides no advantage when reading from a source that is + /// already in memory, like a `Vec`. + /// + /// When the `BufReader` is dropped, the contents of its buffer will be + /// discarded. Creating multiple instances of a `BufReader` on the same + /// stream can cause data loss. + /// + /// [`AsyncRead`]: futures_io::AsyncRead + /// + // TODO: Examples + pub struct BufReader { + #[pin] + inner: R, + buffer: Box<[u8]>, + pos: usize, + cap: usize, + } } impl BufReader { diff --git a/futures-util/src/io/buf_writer.rs b/futures-util/src/io/buf_writer.rs index c45efd3325..991a365a1c 100644 --- a/futures-util/src/io/buf_writer.rs +++ b/futures-util/src/io/buf_writer.rs @@ -1,39 +1,40 @@ use futures_core::ready; use futures_core::task::{Context, Poll}; use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, SeekFrom}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::fmt; use std::io::{self, Write}; use std::pin::Pin; use super::DEFAULT_BUF_SIZE; -/// Wraps a writer and buffers its output. -/// -/// It can be excessively inefficient to work directly with something that -/// implements [`AsyncWrite`]. A `BufWriter` keeps an in-memory buffer of data and -/// writes it to an underlying writer in large, infrequent batches. -/// -/// `BufWriter` can improve the speed of programs that make *small* and -/// *repeated* write calls to the same file or network socket. It does not -/// help when writing very large amounts at once, or writing just one or a few -/// times. It also provides no advantage when writing to a destination that is -/// in memory, like a `Vec`. -/// -/// When the `BufWriter` is dropped, the contents of its buffer will be -/// discarded. Creating multiple instances of a `BufWriter` on the same -/// stream can cause data loss. If you need to write out the contents of its -/// buffer, you must manually call flush before the writer is dropped. -/// -/// [`AsyncWrite`]: futures_io::AsyncWrite -/// [`flush`]: super::AsyncWriteExt::flush -/// -// TODO: Examples -#[pin_project] -pub struct BufWriter { - #[pin] - inner: W, - buf: Vec, - written: usize, +pin_project! { + /// Wraps a writer and buffers its output. + /// + /// It can be excessively inefficient to work directly with something that + /// implements [`AsyncWrite`]. A `BufWriter` keeps an in-memory buffer of data and + /// writes it to an underlying writer in large, infrequent batches. + /// + /// `BufWriter` can improve the speed of programs that make *small* and + /// *repeated* write calls to the same file or network socket. It does not + /// help when writing very large amounts at once, or writing just one or a few + /// times. It also provides no advantage when writing to a destination that is + /// in memory, like a `Vec`. + /// + /// When the `BufWriter` is dropped, the contents of its buffer will be + /// discarded. Creating multiple instances of a `BufWriter` on the same + /// stream can cause data loss. If you need to write out the contents of its + /// buffer, you must manually call flush before the writer is dropped. + /// + /// [`AsyncWrite`]: futures_io::AsyncWrite + /// [`flush`]: super::AsyncWriteExt::flush + /// + // TODO: Examples + pub struct BufWriter { + #[pin] + inner: W, + buf: Vec, + written: usize, + } } impl BufWriter { diff --git a/futures-util/src/io/chain.rs b/futures-util/src/io/chain.rs index 8fbc363b48..1b6a335569 100644 --- a/futures-util/src/io/chain.rs +++ b/futures-util/src/io/chain.rs @@ -3,20 +3,21 @@ use futures_core::task::{Context, Poll}; #[cfg(feature = "read-initializer")] use futures_io::Initializer; use futures_io::{AsyncBufRead, AsyncRead, IoSliceMut}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::fmt; use std::io; use std::pin::Pin; -/// Reader for the [`chain`](super::AsyncReadExt::chain) method. -#[pin_project] -#[must_use = "readers do nothing unless polled"] -pub struct Chain { - #[pin] - first: T, - #[pin] - second: U, - done_first: bool, +pin_project! { + /// Reader for the [`chain`](super::AsyncReadExt::chain) method. + #[must_use = "readers do nothing unless polled"] + pub struct Chain { + #[pin] + first: T, + #[pin] + second: U, + done_first: bool, + } } impl Chain diff --git a/futures-util/src/io/copy.rs b/futures-util/src/io/copy.rs index 491a680a4a..bc592552e9 100644 --- a/futures-util/src/io/copy.rs +++ b/futures-util/src/io/copy.rs @@ -4,7 +4,7 @@ use futures_io::{AsyncRead, AsyncWrite}; use std::io; use std::pin::Pin; use super::{BufReader, copy_buf, CopyBuf}; -use pin_project::pin_project; +use pin_project_lite::pin_project; /// Creates a future which copies all the bytes from one object to another. /// @@ -41,13 +41,14 @@ where } } -/// Future for the [`copy()`] function. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Copy<'a, R, W: ?Sized> { - #[pin] - inner: CopyBuf<'a, BufReader, W>, +pin_project! { + /// Future for the [`copy()`] function. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Copy<'a, R, W: ?Sized> { + #[pin] + inner: CopyBuf<'a, BufReader, W>, + } } impl Future for Copy<'_, R, W> { diff --git a/futures-util/src/io/copy_buf.rs b/futures-util/src/io/copy_buf.rs index 5225c2462b..6adf594d54 100644 --- a/futures-util/src/io/copy_buf.rs +++ b/futures-util/src/io/copy_buf.rs @@ -4,7 +4,7 @@ use futures_core::task::{Context, Poll}; use futures_io::{AsyncBufRead, AsyncWrite}; use std::io; use std::pin::Pin; -use pin_project::pin_project; +use pin_project_lite::pin_project; /// Creates a future which copies all the bytes from one object to another. /// @@ -43,15 +43,16 @@ where } } -/// Future for the [`copy_buf()`] function. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct CopyBuf<'a, R, W: ?Sized> { - #[pin] - reader: R, - writer: &'a mut W, - amt: u64, +pin_project! { + /// Future for the [`copy_buf()`] function. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct CopyBuf<'a, R, W: ?Sized> { + #[pin] + reader: R, + writer: &'a mut W, + amt: u64, + } } impl Future for CopyBuf<'_, R, W> diff --git a/futures-util/src/io/into_sink.rs b/futures-util/src/io/into_sink.rs index f7c20fb9d6..885ba2fb8d 100644 --- a/futures-util/src/io/into_sink.rs +++ b/futures-util/src/io/into_sink.rs @@ -4,7 +4,7 @@ use futures_io::AsyncWrite; use futures_sink::Sink; use std::io; use std::pin::Pin; -use pin_project::pin_project; +use pin_project_lite::pin_project; #[derive(Debug)] struct Block { @@ -12,17 +12,18 @@ struct Block { bytes: Item, } -/// Sink for the [`into_sink`](super::AsyncWriteExt::into_sink) method. -#[pin_project] -#[must_use = "sinks do nothing unless polled"] -#[derive(Debug)] -#[cfg_attr(docsrs, doc(cfg(feature = "sink")))] -pub struct IntoSink { - #[pin] - writer: W, - /// An outstanding block for us to push into the underlying writer, along with an offset of how - /// far into this block we have written already. - buffer: Option>, +pin_project! { + /// Sink for the [`into_sink`](super::AsyncWriteExt::into_sink) method. + #[must_use = "sinks do nothing unless polled"] + #[derive(Debug)] + #[cfg_attr(docsrs, doc(cfg(feature = "sink")))] + pub struct IntoSink { + #[pin] + writer: W, + // An outstanding block for us to push into the underlying writer, along with an offset of how + // far into this block we have written already. + buffer: Option>, + } } impl> IntoSink { diff --git a/futures-util/src/io/lines.rs b/futures-util/src/io/lines.rs index 07257e0eed..6ae7392245 100644 --- a/futures-util/src/io/lines.rs +++ b/futures-util/src/io/lines.rs @@ -6,19 +6,19 @@ use std::io; use std::mem; use std::pin::Pin; use super::read_line::read_line_internal; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`lines`](super::AsyncBufReadExt::lines) method. - -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Lines { - #[pin] - reader: R, - buf: String, - bytes: Vec, - read: usize, +pin_project! { + /// Stream for the [`lines`](super::AsyncBufReadExt::lines) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Lines { + #[pin] + reader: R, + buf: String, + bytes: Vec, + read: usize, + } } impl Lines { diff --git a/futures-util/src/io/take.rs b/futures-util/src/io/take.rs index 0d8b55e3c5..687a69744f 100644 --- a/futures-util/src/io/take.rs +++ b/futures-util/src/io/take.rs @@ -3,19 +3,20 @@ use futures_core::task::{Context, Poll}; #[cfg(feature = "read-initializer")] use futures_io::Initializer; use futures_io::{AsyncRead, AsyncBufRead}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::{cmp, io}; use std::pin::Pin; -/// Reader for the [`take`](super::AsyncReadExt::take) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "readers do nothing unless you `.await` or poll them"] -pub struct Take { - #[pin] - inner: R, - // Add '_' to avoid conflicts with `limit` method. - limit_: u64, +pin_project! { + /// Reader for the [`take`](super::AsyncReadExt::take) method. + #[derive(Debug)] + #[must_use = "readers do nothing unless you `.await` or poll them"] + pub struct Take { + #[pin] + inner: R, + // Add '_' to avoid conflicts with `limit` method. + limit_: u64, + } } impl Take { diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index c9a4d9cef4..5c48d05f98 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -284,10 +284,11 @@ macro_rules! delegate_all { } }; ($(#[$attr:meta])* $name:ident<$($arg:ident),*>($t:ty) : $ftrait:ident $([$($targs:tt)*])* $({$($item:tt)*})* $(where $($bound:tt)*)*) => { - #[pin_project::pin_project] - #[must_use = "futures/streams/sinks do nothing unless you `.await` or poll them"] - $(#[$attr])* - pub struct $name< $($arg),* > $(where $($bound)*)* { #[pin] inner:$t } + pin_project_lite::pin_project! { + #[must_use = "futures/streams/sinks do nothing unless you `.await` or poll them"] + $(#[$attr])* + pub struct $name< $($arg),* > $(where $($bound)*)* { #[pin] inner: $t } + } impl<$($arg),*> $name< $($arg),* > $(where $($bound)*)* { $($($item)*)* diff --git a/futures-util/src/sink/buffer.rs b/futures-util/src/sink/buffer.rs index 3c3f806d93..8c58f4f569 100644 --- a/futures-util/src/sink/buffer.rs +++ b/futures-util/src/sink/buffer.rs @@ -2,21 +2,22 @@ use futures_core::ready; use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::pin::Pin; use alloc::collections::VecDeque; -/// Sink for the [`buffer`](super::SinkExt::buffer) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "sinks do nothing unless polled"] -pub struct Buffer { - #[pin] - sink: Si, - buf: VecDeque, - - // Track capacity separately from the `VecDeque`, which may be rounded up - capacity: usize, +pin_project! { + /// Sink for the [`buffer`](super::SinkExt::buffer) method. + #[derive(Debug)] + #[must_use = "sinks do nothing unless polled"] + pub struct Buffer { + #[pin] + sink: Si, + buf: VecDeque, + + // Track capacity separately from the `VecDeque`, which may be rounded up + capacity: usize, + } } impl, Item> Buffer { diff --git a/futures-util/src/sink/err_into.rs b/futures-util/src/sink/err_into.rs index edad790130..3eb994041f 100644 --- a/futures-util/src/sink/err_into.rs +++ b/futures-util/src/sink/err_into.rs @@ -1,15 +1,16 @@ use crate::sink::{SinkExt, SinkMapErr}; use futures_core::stream::{Stream, FusedStream}; use futures_sink::{Sink}; -use pin_project::pin_project; - -/// Sink for the [`sink_err_into`](super::SinkExt::sink_err_into) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "sinks do nothing unless polled"] -pub struct SinkErrInto, Item, E> { - #[pin] - sink: SinkMapErr E>, +use pin_project_lite::pin_project; + +pin_project! { + /// Sink for the [`sink_err_into`](super::SinkExt::sink_err_into) method. + #[derive(Debug)] + #[must_use = "sinks do nothing unless polled"] + pub struct SinkErrInto, Item, E> { + #[pin] + sink: SinkMapErr E>, + } } impl SinkErrInto diff --git a/futures-util/src/sink/fanout.rs b/futures-util/src/sink/fanout.rs index 19d6bc9f2a..f351e867d4 100644 --- a/futures-util/src/sink/fanout.rs +++ b/futures-util/src/sink/fanout.rs @@ -2,19 +2,20 @@ use core::fmt::{Debug, Formatter, Result as FmtResult}; use core::pin::Pin; use futures_core::task::{Context, Poll}; use futures_sink::Sink; -use pin_project::pin_project; - -/// Sink that clones incoming items and forwards them to two sinks at the same time. -/// -/// Backpressure from any downstream sink propagates up, which means that this sink -/// can only process items as fast as its _slowest_ downstream sink. -#[pin_project] -#[must_use = "sinks do nothing unless polled"] -pub struct Fanout { - #[pin] - sink1: Si1, - #[pin] - sink2: Si2 +use pin_project_lite::pin_project; + +pin_project! { + /// Sink that clones incoming items and forwards them to two sinks at the same time. + /// + /// Backpressure from any downstream sink propagates up, which means that this sink + /// can only process items as fast as its _slowest_ downstream sink. + #[must_use = "sinks do nothing unless polled"] + pub struct Fanout { + #[pin] + sink1: Si1, + #[pin] + sink2: Si2 + } } impl Fanout { diff --git a/futures-util/src/sink/map_err.rs b/futures-util/src/sink/map_err.rs index e77710cc3e..282934465e 100644 --- a/futures-util/src/sink/map_err.rs +++ b/futures-util/src/sink/map_err.rs @@ -2,16 +2,17 @@ use core::pin::Pin; use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; use futures_sink::{Sink}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Sink for the [`sink_map_err`](super::SinkExt::sink_map_err) method. -#[pin_project] -#[derive(Debug, Clone)] -#[must_use = "sinks do nothing unless polled"] -pub struct SinkMapErr { - #[pin] - sink: Si, - f: Option, +pin_project! { + /// Sink for the [`sink_map_err`](super::SinkExt::sink_map_err) method. + #[derive(Debug, Clone)] + #[must_use = "sinks do nothing unless polled"] + pub struct SinkMapErr { + #[pin] + sink: Si, + f: Option, + } } impl SinkMapErr { diff --git a/futures-util/src/sink/unfold.rs b/futures-util/src/sink/unfold.rs index def73c7ade..60c4eac752 100644 --- a/futures-util/src/sink/unfold.rs +++ b/futures-util/src/sink/unfold.rs @@ -2,17 +2,18 @@ use core::{future::Future, pin::Pin}; use futures_core::ready; use futures_core::task::{Context, Poll}; use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Sink for the [`unfold`] function. -#[pin_project] -#[derive(Debug)] -#[must_use = "sinks do nothing unless polled"] -pub struct Unfold { - state: Option, - function: F, - #[pin] - future: Option, +pin_project! { + /// Sink for the [`unfold`] function. + #[derive(Debug)] + #[must_use = "sinks do nothing unless polled"] + pub struct Unfold { + state: Option, + function: F, + #[pin] + future: Option, + } } /// Create a sink from a function which processes one item at a time. diff --git a/futures-util/src/sink/with.rs b/futures-util/src/sink/with.rs index 44894cf9e4..b1d2869541 100644 --- a/futures-util/src/sink/with.rs +++ b/futures-util/src/sink/with.rs @@ -6,18 +6,19 @@ use futures_core::ready; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Sink for the [`with`](super::SinkExt::with) method. -#[pin_project] -#[must_use = "sinks do nothing unless polled"] -pub struct With { - #[pin] - sink: Si, - f: F, - #[pin] - state: Option, - _phantom: PhantomData Item>, +pin_project! { + /// Sink for the [`with`](super::SinkExt::with) method. + #[must_use = "sinks do nothing unless polled"] + pub struct With { + #[pin] + sink: Si, + f: F, + #[pin] + state: Option, + _phantom: PhantomData Item>, + } } impl fmt::Debug for With diff --git a/futures-util/src/sink/with_flat_map.rs b/futures-util/src/sink/with_flat_map.rs index 5e74930e6d..4b8d3a275c 100644 --- a/futures-util/src/sink/with_flat_map.rs +++ b/futures-util/src/sink/with_flat_map.rs @@ -5,19 +5,20 @@ use futures_core::ready; use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Sink for the [`with_flat_map`](super::SinkExt::with_flat_map) method. -#[pin_project] -#[must_use = "sinks do nothing unless polled"] -pub struct WithFlatMap { - #[pin] - sink: Si, - f: F, - #[pin] - stream: Option, - buffer: Option, - _marker: PhantomData, +pin_project! { + /// Sink for the [`with_flat_map`](super::SinkExt::with_flat_map) method. + #[must_use = "sinks do nothing unless polled"] + pub struct WithFlatMap { + #[pin] + sink: Si, + f: F, + #[pin] + stream: Option, + buffer: Option, + _marker: PhantomData, + } } impl fmt::Debug for WithFlatMap diff --git a/futures-util/src/stream/futures_ordered.rs b/futures-util/src/stream/futures_ordered.rs index 2943304cc5..eda3b27038 100644 --- a/futures-util/src/stream/futures_ordered.rs +++ b/futures-util/src/stream/futures_ordered.rs @@ -1,22 +1,26 @@ use crate::stream::{FuturesUnordered, StreamExt}; -use futures_core::future::Future; -use futures_core::stream::Stream; -use futures_core::{FusedStream, task::{Context, Poll}}; -use futures_core::ready; -use pin_project::pin_project; +use alloc::collections::binary_heap::{BinaryHeap, PeekMut}; use core::cmp::Ordering; use core::fmt::{self, Debug}; use core::iter::FromIterator; use core::pin::Pin; -use alloc::collections::binary_heap::{BinaryHeap, PeekMut}; - -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -#[derive(Debug)] -struct OrderWrapper { - #[pin] - data: T, // A future or a future's output - index: usize, +use futures_core::future::Future; +use futures_core::ready; +use futures_core::stream::Stream; +use futures_core::{ + task::{Context, Poll}, + FusedStream, +}; +use pin_project_lite::pin_project; + +pin_project! { + #[must_use = "futures do nothing unless you `.await` or poll them"] + #[derive(Debug)] + struct OrderWrapper { + #[pin] + data: T, // A future or a future's output + index: usize, + } } impl PartialEq for OrderWrapper { @@ -41,17 +45,17 @@ impl Ord for OrderWrapper { } impl Future for OrderWrapper - where T: Future +where + T: Future, { type Output = OrderWrapper; - fn poll( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll { + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let index = self.index; - self.project().data.poll(cx) - .map(|output| OrderWrapper { data: output, index }) + self.project().data.poll(cx).map(|output| OrderWrapper { + data: output, + index, + }) } } @@ -153,10 +157,7 @@ impl Default for FuturesOrdered { impl Stream for FuturesOrdered { type Item = Fut::Output; - fn poll_next( - mut self: Pin<&mut Self>, - cx: &mut Context<'_> - ) -> Poll> { + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = &mut *self; // Check to see if we've already received the next value @@ -200,7 +201,10 @@ impl FromIterator for FuturesOrdered { T: IntoIterator, { let acc = Self::new(); - iter.into_iter().fold(acc, |mut acc, item| { acc.push(item); acc }) + iter.into_iter().fold(acc, |mut acc, item| { + acc.push(item); + acc + }) } } diff --git a/futures-util/src/stream/once.rs b/futures-util/src/stream/once.rs index f0568378ea..318de076d1 100644 --- a/futures-util/src/stream/once.rs +++ b/futures-util/src/stream/once.rs @@ -3,7 +3,7 @@ use futures_core::future::Future; use futures_core::ready; use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; /// Creates a stream of a single element. /// @@ -20,13 +20,14 @@ pub fn once(future: Fut) -> Once { Once::new(future) } -/// A stream which emits single element and then EOF. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Once { - #[pin] - future: Option +pin_project! { + /// A stream which emits single element and then EOF. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Once { + #[pin] + future: Option + } } impl Once { diff --git a/futures-util/src/stream/select.rs b/futures-util/src/stream/select.rs index 7666386431..2b7ebec5d6 100644 --- a/futures-util/src/stream/select.rs +++ b/futures-util/src/stream/select.rs @@ -2,18 +2,19 @@ use crate::stream::{StreamExt, Fuse}; use core::pin::Pin; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`select()`] function. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Select { - #[pin] - stream1: Fuse, - #[pin] - stream2: Fuse, - flag: bool, +pin_project! { + /// Stream for the [`select()`] function. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Select { + #[pin] + stream1: Fuse, + #[pin] + stream2: Fuse, + flag: bool, + } } /// This function will attempt to pull items from both streams. Each diff --git a/futures-util/src/stream/stream/buffer_unordered.rs b/futures-util/src/stream/stream/buffer_unordered.rs index 4ae3c50b1e..de42cfd330 100644 --- a/futures-util/src/stream/stream/buffer_unordered.rs +++ b/futures-util/src/stream/stream/buffer_unordered.rs @@ -4,22 +4,23 @@ use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::fmt; use core::pin::Pin; -/// Stream for the [`buffer_unordered`](super::StreamExt::buffer_unordered) -/// method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct BufferUnordered -where - St: Stream, -{ - #[pin] - stream: Fuse, - in_progress_queue: FuturesUnordered, - max: usize, +pin_project! { + /// Stream for the [`buffer_unordered`](super::StreamExt::buffer_unordered) + /// method. + #[must_use = "streams do nothing unless polled"] + pub struct BufferUnordered + where + St: Stream, + { + #[pin] + stream: Fuse, + in_progress_queue: FuturesUnordered, + max: usize, + } } impl fmt::Debug for BufferUnordered diff --git a/futures-util/src/stream/stream/buffered.rs b/futures-util/src/stream/stream/buffered.rs index 34fd828a38..1af9f492b9 100644 --- a/futures-util/src/stream/stream/buffered.rs +++ b/futures-util/src/stream/stream/buffered.rs @@ -5,22 +5,23 @@ use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::fmt; use core::pin::Pin; -/// Stream for the [`buffered`](super::StreamExt::buffered) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct Buffered -where - St: Stream, - St::Item: Future, -{ - #[pin] - stream: Fuse, - in_progress_queue: FuturesOrdered, - max: usize, +pin_project! { + /// Stream for the [`buffered`](super::StreamExt::buffered) method. + #[must_use = "streams do nothing unless polled"] + pub struct Buffered + where + St: Stream, + St::Item: Future, + { + #[pin] + stream: Fuse, + in_progress_queue: FuturesOrdered, + max: usize, + } } impl fmt::Debug for Buffered diff --git a/futures-util/src/stream/stream/catch_unwind.rs b/futures-util/src/stream/stream/catch_unwind.rs index 20769ae23f..d87a40a2e3 100644 --- a/futures-util/src/stream/stream/catch_unwind.rs +++ b/futures-util/src/stream/stream/catch_unwind.rs @@ -1,18 +1,19 @@ use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::any::Any; use std::pin::Pin; use std::panic::{catch_unwind, UnwindSafe, AssertUnwindSafe}; -/// Stream for the [`catch_unwind`](super::StreamExt::catch_unwind) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct CatchUnwind { - #[pin] - stream: St, - caught_unwind: bool, +pin_project! { + /// Stream for the [`catch_unwind`](super::StreamExt::catch_unwind) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct CatchUnwind { + #[pin] + stream: St, + caught_unwind: bool, + } } impl CatchUnwind { diff --git a/futures-util/src/stream/stream/chain.rs b/futures-util/src/stream/stream/chain.rs index e7508f978b..2be710462a 100644 --- a/futures-util/src/stream/stream/chain.rs +++ b/futures-util/src/stream/stream/chain.rs @@ -2,17 +2,18 @@ use core::pin::Pin; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`chain`](super::StreamExt::chain) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Chain { - #[pin] - first: Option, - #[pin] - second: St2, +pin_project! { + /// Stream for the [`chain`](super::StreamExt::chain) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Chain { + #[pin] + first: Option, + #[pin] + second: St2, + } } // All interactions with `Pin<&mut Chain<..>>` happen through these methods diff --git a/futures-util/src/stream/stream/chunks.rs b/futures-util/src/stream/stream/chunks.rs index b98478961b..45a3212582 100644 --- a/futures-util/src/stream/stream/chunks.rs +++ b/futures-util/src/stream/stream/chunks.rs @@ -4,20 +4,21 @@ use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::mem; use core::pin::Pin; use alloc::vec::Vec; -/// Stream for the [`chunks`](super::StreamExt::chunks) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Chunks { - #[pin] - stream: Fuse, - items: Vec, - cap: usize, // https://github.com/rust-lang/futures-rs/issues/1475 +pin_project! { + /// Stream for the [`chunks`](super::StreamExt::chunks) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Chunks { + #[pin] + stream: Fuse, + items: Vec, + cap: usize, // https://github.com/rust-lang/futures-rs/issues/1475 + } } impl Chunks where St: Stream { diff --git a/futures-util/src/stream/stream/collect.rs b/futures-util/src/stream/stream/collect.rs index 6307650a45..774b34b39a 100644 --- a/futures-util/src/stream/stream/collect.rs +++ b/futures-util/src/stream/stream/collect.rs @@ -4,16 +4,17 @@ use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`collect`](super::StreamExt::collect) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Collect { - #[pin] - stream: St, - collection: C, +pin_project! { + /// Future for the [`collect`](super::StreamExt::collect) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Collect { + #[pin] + stream: St, + collection: C, + } } impl Collect { diff --git a/futures-util/src/stream/stream/concat.rs b/futures-util/src/stream/stream/concat.rs index b61b71254b..ee1349f86d 100644 --- a/futures-util/src/stream/stream/concat.rs +++ b/futures-util/src/stream/stream/concat.rs @@ -3,16 +3,17 @@ use futures_core::future::{Future, FusedFuture}; use futures_core::ready; use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`concat`](super::StreamExt::concat) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Concat { - #[pin] - stream: St, - accum: Option, +pin_project! { + /// Future for the [`concat`](super::StreamExt::concat) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Concat { + #[pin] + stream: St, + accum: Option, + } } impl Concat diff --git a/futures-util/src/stream/stream/cycle.rs b/futures-util/src/stream/stream/cycle.rs index 1f6e5f682d..a5b7dc08c5 100644 --- a/futures-util/src/stream/stream/cycle.rs +++ b/futures-util/src/stream/stream/cycle.rs @@ -3,16 +3,17 @@ use core::usize; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`cycle`](super::StreamExt::cycle) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Cycle { - orig: St, - #[pin] - stream: St, +pin_project! { + /// Stream for the [`cycle`](super::StreamExt::cycle) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Cycle { + orig: St, + #[pin] + stream: St, + } } impl Cycle diff --git a/futures-util/src/stream/stream/enumerate.rs b/futures-util/src/stream/stream/enumerate.rs index e896f79ba2..7d4c9cbe68 100644 --- a/futures-util/src/stream/stream/enumerate.rs +++ b/futures-util/src/stream/stream/enumerate.rs @@ -4,16 +4,17 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`enumerate`](super::StreamExt::enumerate) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Enumerate { - #[pin] - stream: St, - count: usize, +pin_project! { + /// Stream for the [`enumerate`](super::StreamExt::enumerate) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Enumerate { + #[pin] + stream: St, + count: usize, + } } impl Enumerate { diff --git a/futures-util/src/stream/stream/filter.rs b/futures-util/src/stream/stream/filter.rs index 6e8eefaf0e..57de0253a4 100644 --- a/futures-util/src/stream/stream/filter.rs +++ b/futures-util/src/stream/stream/filter.rs @@ -6,21 +6,22 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use crate::fns::FnMut1; -/// Stream for the [`filter`](super::StreamExt::filter) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct Filter - where St: Stream, -{ - #[pin] - stream: St, - f: F, - #[pin] - pending_fut: Option, - pending_item: Option, +pin_project! { + /// Stream for the [`filter`](super::StreamExt::filter) method. + #[must_use = "streams do nothing unless polled"] + pub struct Filter + where St: Stream, + { + #[pin] + stream: St, + f: F, + #[pin] + pending_fut: Option, + pending_item: Option, + } } impl fmt::Debug for Filter diff --git a/futures-util/src/stream/stream/filter_map.rs b/futures-util/src/stream/stream/filter_map.rs index fbb2ba4baa..b762face28 100644 --- a/futures-util/src/stream/stream/filter_map.rs +++ b/futures-util/src/stream/stream/filter_map.rs @@ -6,18 +6,19 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use crate::fns::FnMut1; -/// Stream for the [`filter_map`](super::StreamExt::filter_map) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct FilterMap { - #[pin] - stream: St, - f: F, - #[pin] - pending: Option, +pin_project! { + /// Stream for the [`filter_map`](super::StreamExt::filter_map) method. + #[must_use = "streams do nothing unless polled"] + pub struct FilterMap { + #[pin] + stream: St, + f: F, + #[pin] + pending: Option, + } } impl fmt::Debug for FilterMap diff --git a/futures-util/src/stream/stream/flatten.rs b/futures-util/src/stream/stream/flatten.rs index 70d68d550b..9f6b7a472d 100644 --- a/futures-util/src/stream/stream/flatten.rs +++ b/futures-util/src/stream/stream/flatten.rs @@ -4,17 +4,18 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`flatten`](super::StreamExt::flatten) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Flatten { - #[pin] - stream: St, - #[pin] - next: Option, +pin_project! { + /// Stream for the [`flatten`](super::StreamExt::flatten) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Flatten { + #[pin] + stream: St, + #[pin] + next: Option, + } } impl Flatten { diff --git a/futures-util/src/stream/stream/fold.rs b/futures-util/src/stream/stream/fold.rs index bc8ff24c8e..e109c3bdcf 100644 --- a/futures-util/src/stream/stream/fold.rs +++ b/futures-util/src/stream/stream/fold.rs @@ -4,18 +4,19 @@ use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`fold`](super::StreamExt::fold) method. -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Fold { - #[pin] - stream: St, - f: F, - accum: Option, - #[pin] - future: Option, +pin_project! { + /// Future for the [`fold`](super::StreamExt::fold) method. + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Fold { + #[pin] + stream: St, + f: F, + accum: Option, + #[pin] + future: Option, + } } impl fmt::Debug for Fold diff --git a/futures-util/src/stream/stream/for_each.rs b/futures-util/src/stream/stream/for_each.rs index 2f8e727e05..ee90e66610 100644 --- a/futures-util/src/stream/stream/for_each.rs +++ b/futures-util/src/stream/stream/for_each.rs @@ -4,17 +4,18 @@ use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`for_each`](super::StreamExt::for_each) method. -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct ForEach { - #[pin] - stream: St, - f: F, - #[pin] - future: Option, +pin_project! { + /// Future for the [`for_each`](super::StreamExt::for_each) method. + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct ForEach { + #[pin] + stream: St, + f: F, + #[pin] + future: Option, + } } impl fmt::Debug for ForEach diff --git a/futures-util/src/stream/stream/for_each_concurrent.rs b/futures-util/src/stream/stream/for_each_concurrent.rs index dc032f489c..cee0ba197e 100644 --- a/futures-util/src/stream/stream/for_each_concurrent.rs +++ b/futures-util/src/stream/stream/for_each_concurrent.rs @@ -5,18 +5,19 @@ use core::num::NonZeroUsize; use futures_core::future::{FusedFuture, Future}; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`for_each_concurrent`](super::StreamExt::for_each_concurrent) -/// method. -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct ForEachConcurrent { - #[pin] - stream: Option, - f: F, - futures: FuturesUnordered, - limit: Option, +pin_project! { + /// Future for the [`for_each_concurrent`](super::StreamExt::for_each_concurrent) + /// method. + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct ForEachConcurrent { + #[pin] + stream: Option, + f: F, + futures: FuturesUnordered, + limit: Option, + } } impl fmt::Debug for ForEachConcurrent diff --git a/futures-util/src/stream/stream/forward.rs b/futures-util/src/stream/stream/forward.rs index 243496d451..2247b21e97 100644 --- a/futures-util/src/stream/stream/forward.rs +++ b/futures-util/src/stream/stream/forward.rs @@ -5,18 +5,20 @@ use futures_core::ready; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`forward`](super::StreamExt::forward) method. -#[pin_project(project = ForwardProj)] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Forward { - #[pin] - sink: Option, - #[pin] - stream: Fuse, - buffered_item: Option, +pin_project! { + /// Future for the [`forward`](super::StreamExt::forward) method. + #[project = ForwardProj] + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Forward { + #[pin] + sink: Option, + #[pin] + stream: Fuse, + buffered_item: Option, + } } impl Forward { diff --git a/futures-util/src/stream/stream/fuse.rs b/futures-util/src/stream/stream/fuse.rs index f0cb885bc2..e1d8c122b3 100644 --- a/futures-util/src/stream/stream/fuse.rs +++ b/futures-util/src/stream/stream/fuse.rs @@ -4,16 +4,17 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`fuse`](super::StreamExt::fuse) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Fuse { - #[pin] - stream: St, - done: bool, +pin_project! { + /// Stream for the [`fuse`](super::StreamExt::fuse) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Fuse { + #[pin] + stream: St, + done: bool, + } } impl Fuse { diff --git a/futures-util/src/stream/stream/map.rs b/futures-util/src/stream/stream/map.rs index 8292892a8e..1a269f0c30 100644 --- a/futures-util/src/stream/stream/map.rs +++ b/futures-util/src/stream/stream/map.rs @@ -5,17 +5,18 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use crate::fns::FnMut1; -/// Stream for the [`map`](super::StreamExt::map) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct Map { - #[pin] - stream: St, - f: F, +pin_project! { + /// Stream for the [`map`](super::StreamExt::map) method. + #[must_use = "streams do nothing unless polled"] + pub struct Map { + #[pin] + stream: St, + f: F, + } } impl fmt::Debug for Map diff --git a/futures-util/src/stream/stream/peek.rs b/futures-util/src/stream/stream/peek.rs index bd29c5d957..a4031102ab 100644 --- a/futures-util/src/stream/stream/peek.rs +++ b/futures-util/src/stream/stream/peek.rs @@ -7,20 +7,21 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; - -/// A `Stream` that implements a `peek` method. -/// -/// The `peek` method can be used to retrieve a reference -/// to the next `Stream::Item` if available. A subsequent -/// call to `poll` will return the owned item. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Peekable { - #[pin] - stream: Fuse, - peeked: Option, +use pin_project_lite::pin_project; + +pin_project! { + /// A `Stream` that implements a `peek` method. + /// + /// The `peek` method can be used to retrieve a reference + /// to the next `Stream::Item` if available. A subsequent + /// call to `poll` will return the owned item. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Peekable { + #[pin] + stream: Fuse, + peeked: Option, + } } impl Peekable { @@ -101,11 +102,12 @@ where delegate_sink!(stream, Item); } -/// Future for the [`Peekable::peek()`](self::Peekable::peek) function from [`Peekable`] -#[pin_project] -#[must_use = "futures do nothing unless polled"] -pub struct Peek<'a, St: Stream> { - inner: Option>>, +pin_project! { + /// Future for the [`Peekable::peek()`](self::Peekable::peek) function from [`Peekable`] + #[must_use = "futures do nothing unless polled"] + pub struct Peek<'a, St: Stream> { + inner: Option>>, + } } impl fmt::Debug for Peek<'_, St> diff --git a/futures-util/src/stream/stream/ready_chunks.rs b/futures-util/src/stream/stream/ready_chunks.rs index 6cc51a5d78..b6e3e5c2de 100644 --- a/futures-util/src/stream/stream/ready_chunks.rs +++ b/futures-util/src/stream/stream/ready_chunks.rs @@ -3,20 +3,21 @@ use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::mem; use core::pin::Pin; use alloc::vec::Vec; -/// Stream for the [`ready_chunks`](super::StreamExt::ready_chunks) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct ReadyChunks { - #[pin] - stream: Fuse, - items: Vec, - cap: usize, // https://github.com/rust-lang/futures-rs/issues/1475 +pin_project! { + /// Stream for the [`ready_chunks`](super::StreamExt::ready_chunks) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct ReadyChunks { + #[pin] + stream: Fuse, + items: Vec, + cap: usize, // https://github.com/rust-lang/futures-rs/issues/1475 + } } impl ReadyChunks where St: Stream { diff --git a/futures-util/src/stream/stream/scan.rs b/futures-util/src/stream/stream/scan.rs index f3ae7cf56c..20972807ce 100644 --- a/futures-util/src/stream/stream/scan.rs +++ b/futures-util/src/stream/stream/scan.rs @@ -6,22 +6,23 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; struct StateFn { state: S, f: F, } -/// Stream for the [`scan`](super::StreamExt::scan) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct Scan { - #[pin] - stream: St, - state_f: Option>, - #[pin] - future: Option, +pin_project! { + /// Stream for the [`scan`](super::StreamExt::scan) method. + #[must_use = "streams do nothing unless polled"] + pub struct Scan { + #[pin] + stream: St, + state_f: Option>, + #[pin] + future: Option, + } } impl fmt::Debug for Scan diff --git a/futures-util/src/stream/stream/skip.rs b/futures-util/src/stream/stream/skip.rs index 17d5776837..6ffcf57d77 100644 --- a/futures-util/src/stream/stream/skip.rs +++ b/futures-util/src/stream/stream/skip.rs @@ -4,16 +4,17 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`skip`](super::StreamExt::skip) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Skip { - #[pin] - stream: St, - remaining: usize, +pin_project! { + /// Stream for the [`skip`](super::StreamExt::skip) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Skip { + #[pin] + stream: St, + remaining: usize, + } } impl Skip { diff --git a/futures-util/src/stream/stream/skip_while.rs b/futures-util/src/stream/stream/skip_while.rs index fb4f056134..e1aa3f904b 100644 --- a/futures-util/src/stream/stream/skip_while.rs +++ b/futures-util/src/stream/stream/skip_while.rs @@ -6,19 +6,20 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`skip_while`](super::StreamExt::skip_while) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct SkipWhile where St: Stream { - #[pin] - stream: St, - f: F, - #[pin] - pending_fut: Option, - pending_item: Option, - done_skipping: bool, +pin_project! { + /// Stream for the [`skip_while`](super::StreamExt::skip_while) method. + #[must_use = "streams do nothing unless polled"] + pub struct SkipWhile where St: Stream { + #[pin] + stream: St, + f: F, + #[pin] + pending_fut: Option, + pending_item: Option, + done_skipping: bool, + } } impl fmt::Debug for SkipWhile diff --git a/futures-util/src/stream/stream/take.rs b/futures-util/src/stream/stream/take.rs index b8b2b679f1..124d397c46 100644 --- a/futures-util/src/stream/stream/take.rs +++ b/futures-util/src/stream/stream/take.rs @@ -5,16 +5,17 @@ use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`take`](super::StreamExt::take) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Take { - #[pin] - stream: St, - remaining: usize, +pin_project! { + /// Stream for the [`take`](super::StreamExt::take) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Take { + #[pin] + stream: St, + remaining: usize, + } } impl Take { diff --git a/futures-util/src/stream/stream/take_until.rs b/futures-util/src/stream/stream/take_until.rs index 409b5fa9f7..4dea01aae9 100644 --- a/futures-util/src/stream/stream/take_until.rs +++ b/futures-util/src/stream/stream/take_until.rs @@ -6,24 +6,25 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; // FIXME: docs, tests -/// Stream for the [`take_until`](super::StreamExt::take_until) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TakeUntil { - #[pin] - stream: St, - /// Contains the inner Future on start and None once the inner Future is resolved - /// or taken out by the user. - #[pin] - fut: Option, - /// Contains fut's return value once fut is resolved - fut_result: Option, - /// Whether the future was taken out by the user. - free: bool, +pin_project! { + /// Stream for the [`take_until`](super::StreamExt::take_until) method. + #[must_use = "streams do nothing unless polled"] + pub struct TakeUntil { + #[pin] + stream: St, + // Contains the inner Future on start and None once the inner Future is resolved + // or taken out by the user. + #[pin] + fut: Option, + // Contains fut's return value once fut is resolved + fut_result: Option, + // Whether the future was taken out by the user. + free: bool, + } } impl fmt::Debug for TakeUntil diff --git a/futures-util/src/stream/stream/take_while.rs b/futures-util/src/stream/stream/take_while.rs index 486dc6e779..4cdba83564 100644 --- a/futures-util/src/stream/stream/take_while.rs +++ b/futures-util/src/stream/stream/take_while.rs @@ -6,19 +6,20 @@ use futures_core::stream::{Stream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`take_while`](super::StreamExt::take_while) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TakeWhile { - #[pin] - stream: St, - f: F, - #[pin] - pending_fut: Option, - pending_item: Option, - done_taking: bool, +pin_project! { + /// Stream for the [`take_while`](super::StreamExt::take_while) method. + #[must_use = "streams do nothing unless polled"] + pub struct TakeWhile { + #[pin] + stream: St, + f: F, + #[pin] + pending_fut: Option, + pending_item: Option, + done_taking: bool, + } } impl fmt::Debug for TakeWhile diff --git a/futures-util/src/stream/stream/then.rs b/futures-util/src/stream/stream/then.rs index 71a3044dbe..3d42bdd5c2 100644 --- a/futures-util/src/stream/stream/then.rs +++ b/futures-util/src/stream/stream/then.rs @@ -6,17 +6,18 @@ use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`then`](super::StreamExt::then) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct Then { - #[pin] - stream: St, - #[pin] - future: Option, - f: F, +pin_project! { + /// Stream for the [`then`](super::StreamExt::then) method. + #[must_use = "streams do nothing unless polled"] + pub struct Then { + #[pin] + stream: St, + #[pin] + future: Option, + f: F, + } } impl fmt::Debug for Then diff --git a/futures-util/src/stream/stream/unzip.rs b/futures-util/src/stream/stream/unzip.rs index 697ec28171..5024770769 100644 --- a/futures-util/src/stream/stream/unzip.rs +++ b/futures-util/src/stream/stream/unzip.rs @@ -4,17 +4,18 @@ use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`unzip`](super::StreamExt::unzip) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct Unzip { - #[pin] - stream: St, - left: FromA, - right: FromB, +pin_project! { + /// Future for the [`unzip`](super::StreamExt::unzip) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct Unzip { + #[pin] + stream: St, + left: FromA, + right: FromB, + } } impl Unzip { diff --git a/futures-util/src/stream/stream/zip.rs b/futures-util/src/stream/stream/zip.rs index 244748e9e5..588531a468 100644 --- a/futures-util/src/stream/stream/zip.rs +++ b/futures-util/src/stream/stream/zip.rs @@ -3,19 +3,20 @@ use core::cmp; use core::pin::Pin; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; - -/// Stream for the [`zip`](super::StreamExt::zip) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct Zip { - #[pin] - stream1: Fuse, - #[pin] - stream2: Fuse, - queued1: Option, - queued2: Option, +use pin_project_lite::pin_project; + +pin_project! { + /// Stream for the [`zip`](super::StreamExt::zip) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct Zip { + #[pin] + stream1: Fuse, + #[pin] + stream2: Fuse, + queued1: Option, + queued2: Option, + } } impl Zip { diff --git a/futures-util/src/stream/try_stream/and_then.rs b/futures-util/src/stream/try_stream/and_then.rs index 025a3c6b2f..b18564649a 100644 --- a/futures-util/src/stream/try_stream/and_then.rs +++ b/futures-util/src/stream/try_stream/and_then.rs @@ -6,17 +6,18 @@ use futures_core::stream::{Stream, TryStream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`and_then`](super::TryStreamExt::and_then) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct AndThen { - #[pin] - stream: St, - #[pin] - future: Option, - f: F, +pin_project! { + /// Stream for the [`and_then`](super::TryStreamExt::and_then) method. + #[must_use = "streams do nothing unless polled"] + pub struct AndThen { + #[pin] + stream: St, + #[pin] + future: Option, + f: F, + } } impl fmt::Debug for AndThen diff --git a/futures-util/src/stream/try_stream/into_stream.rs b/futures-util/src/stream/try_stream/into_stream.rs index b466673c82..89bc3ef177 100644 --- a/futures-util/src/stream/try_stream/into_stream.rs +++ b/futures-util/src/stream/try_stream/into_stream.rs @@ -3,15 +3,16 @@ use futures_core::stream::{FusedStream, Stream, TryStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; - -/// Stream for the [`into_stream`](super::TryStreamExt::into_stream) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct IntoStream { - #[pin] - stream: St, +use pin_project_lite::pin_project; + +pin_project! { + /// Stream for the [`into_stream`](super::TryStreamExt::into_stream) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct IntoStream { + #[pin] + stream: St, + } } impl IntoStream { diff --git a/futures-util/src/stream/try_stream/or_else.rs b/futures-util/src/stream/try_stream/or_else.rs index f66592f50e..999123a437 100644 --- a/futures-util/src/stream/try_stream/or_else.rs +++ b/futures-util/src/stream/try_stream/or_else.rs @@ -6,17 +6,18 @@ use futures_core::stream::{Stream, TryStream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`or_else`](super::TryStreamExt::or_else) method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct OrElse { - #[pin] - stream: St, - #[pin] - future: Option, - f: F, +pin_project! { + /// Stream for the [`or_else`](super::TryStreamExt::or_else) method. + #[must_use = "streams do nothing unless polled"] + pub struct OrElse { + #[pin] + stream: St, + #[pin] + future: Option, + f: F, + } } impl fmt::Debug for OrElse diff --git a/futures-util/src/stream/try_stream/try_buffer_unordered.rs b/futures-util/src/stream/try_stream/try_buffer_unordered.rs index 6ab548c13c..71c6fc7e26 100644 --- a/futures-util/src/stream/try_stream/try_buffer_unordered.rs +++ b/futures-util/src/stream/try_stream/try_buffer_unordered.rs @@ -5,21 +5,22 @@ use futures_core::stream::{Stream, TryStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::pin::Pin; -/// Stream for the -/// [`try_buffer_unordered`](super::TryStreamExt::try_buffer_unordered) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct TryBufferUnordered - where St: TryStream -{ - #[pin] - stream: Fuse>, - in_progress_queue: FuturesUnordered>, - max: usize, +pin_project! { + /// Stream for the + /// [`try_buffer_unordered`](super::TryStreamExt::try_buffer_unordered) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct TryBufferUnordered + where St: TryStream + { + #[pin] + stream: Fuse>, + in_progress_queue: FuturesUnordered>, + max: usize, + } } impl TryBufferUnordered diff --git a/futures-util/src/stream/try_stream/try_buffered.rs b/futures-util/src/stream/try_stream/try_buffered.rs index 4e16d3d46d..ff7e8447f9 100644 --- a/futures-util/src/stream/try_stream/try_buffered.rs +++ b/futures-util/src/stream/try_stream/try_buffered.rs @@ -5,22 +5,23 @@ use futures_core::stream::{Stream, TryStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; use core::pin::Pin; -/// Stream for the [`try_buffered`](super::TryStreamExt::try_buffered) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct TryBuffered -where - St: TryStream, - St::Ok: TryFuture, -{ - #[pin] - stream: Fuse>, - in_progress_queue: FuturesOrdered>, - max: usize, +pin_project! { + /// Stream for the [`try_buffered`](super::TryStreamExt::try_buffered) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct TryBuffered + where + St: TryStream, + St::Ok: TryFuture, + { + #[pin] + stream: Fuse>, + in_progress_queue: FuturesOrdered>, + max: usize, + } } impl TryBuffered diff --git a/futures-util/src/stream/try_stream/try_collect.rs b/futures-util/src/stream/try_stream/try_collect.rs index 66366da9fd..387de9703b 100644 --- a/futures-util/src/stream/try_stream/try_collect.rs +++ b/futures-util/src/stream/try_stream/try_collect.rs @@ -4,16 +4,17 @@ use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::{FusedStream, TryStream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`try_collect`](super::TryStreamExt::try_collect) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct TryCollect { - #[pin] - stream: St, - items: C, +pin_project! { + /// Future for the [`try_collect`](super::TryStreamExt::try_collect) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct TryCollect { + #[pin] + stream: St, + items: C, + } } impl TryCollect { diff --git a/futures-util/src/stream/try_stream/try_concat.rs b/futures-util/src/stream/try_stream/try_concat.rs index cd14b8861d..2451332448 100644 --- a/futures-util/src/stream/try_stream/try_concat.rs +++ b/futures-util/src/stream/try_stream/try_concat.rs @@ -3,16 +3,17 @@ use futures_core::future::Future; use futures_core::ready; use futures_core::stream::TryStream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`try_concat`](super::TryStreamExt::try_concat) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct TryConcat { - #[pin] - stream: St, - accum: Option, +pin_project! { + /// Future for the [`try_concat`](super::TryStreamExt::try_concat) method. + #[derive(Debug)] + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct TryConcat { + #[pin] + stream: St, + accum: Option, + } } impl TryConcat diff --git a/futures-util/src/stream/try_stream/try_filter.rs b/futures-util/src/stream/try_stream/try_filter.rs index 36c3e7af62..eacefd20db 100644 --- a/futures-util/src/stream/try_stream/try_filter.rs +++ b/futures-util/src/stream/try_stream/try_filter.rs @@ -6,21 +6,22 @@ use futures_core::stream::{Stream, TryStream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`try_filter`](super::TryStreamExt::try_filter) -/// method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TryFilter - where St: TryStream -{ - #[pin] - stream: St, - f: F, - #[pin] - pending_fut: Option, - pending_item: Option, +pin_project! { + /// Stream for the [`try_filter`](super::TryStreamExt::try_filter) + /// method. + #[must_use = "streams do nothing unless polled"] + pub struct TryFilter + where St: TryStream + { + #[pin] + stream: St, + f: F, + #[pin] + pending_fut: Option, + pending_item: Option, + } } impl fmt::Debug for TryFilter diff --git a/futures-util/src/stream/try_stream/try_filter_map.rs b/futures-util/src/stream/try_stream/try_filter_map.rs index 397254281c..335649bfc9 100644 --- a/futures-util/src/stream/try_stream/try_filter_map.rs +++ b/futures-util/src/stream/try_stream/try_filter_map.rs @@ -6,18 +6,19 @@ use futures_core::stream::{Stream, TryStream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`try_filter_map`](super::TryStreamExt::try_filter_map) -/// method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TryFilterMap { - #[pin] - stream: St, - f: F, - #[pin] - pending: Option, +pin_project! { + /// Stream for the [`try_filter_map`](super::TryStreamExt::try_filter_map) + /// method. + #[must_use = "streams do nothing unless polled"] + pub struct TryFilterMap { + #[pin] + stream: St, + f: F, + #[pin] + pending: Option, + } } impl fmt::Debug for TryFilterMap diff --git a/futures-util/src/stream/try_stream/try_flatten.rs b/futures-util/src/stream/try_stream/try_flatten.rs index 5593161077..4fc04a07bb 100644 --- a/futures-util/src/stream/try_stream/try_flatten.rs +++ b/futures-util/src/stream/try_stream/try_flatten.rs @@ -4,20 +4,21 @@ use futures_core::stream::{FusedStream, Stream, TryStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`try_flatten`](super::TryStreamExt::try_flatten) method. -#[pin_project] -#[derive(Debug)] -#[must_use = "streams do nothing unless polled"] -pub struct TryFlatten -where - St: TryStream, -{ - #[pin] - stream: St, - #[pin] - next: Option, +pin_project! { + /// Stream for the [`try_flatten`](super::TryStreamExt::try_flatten) method. + #[derive(Debug)] + #[must_use = "streams do nothing unless polled"] + pub struct TryFlatten + where + St: TryStream, + { + #[pin] + stream: St, + #[pin] + next: Option, + } } impl TryFlatten diff --git a/futures-util/src/stream/try_stream/try_fold.rs b/futures-util/src/stream/try_stream/try_fold.rs index d8ef37b267..1d41e4bc2b 100644 --- a/futures-util/src/stream/try_stream/try_fold.rs +++ b/futures-util/src/stream/try_stream/try_fold.rs @@ -4,18 +4,19 @@ use futures_core::future::{FusedFuture, Future, TryFuture}; use futures_core::ready; use futures_core::stream::TryStream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`try_fold`](super::TryStreamExt::try_fold) method. -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct TryFold { - #[pin] - stream: St, - f: F, - accum: Option, - #[pin] - future: Option, +pin_project! { + /// Future for the [`try_fold`](super::TryStreamExt::try_fold) method. + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct TryFold { + #[pin] + stream: St, + f: F, + accum: Option, + #[pin] + future: Option, + } } impl fmt::Debug for TryFold diff --git a/futures-util/src/stream/try_stream/try_for_each.rs b/futures-util/src/stream/try_stream/try_for_each.rs index cf8fefce54..0a814ae86c 100644 --- a/futures-util/src/stream/try_stream/try_for_each.rs +++ b/futures-util/src/stream/try_stream/try_for_each.rs @@ -4,17 +4,18 @@ use futures_core::future::{Future, TryFuture}; use futures_core::ready; use futures_core::stream::TryStream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the [`try_for_each`](super::TryStreamExt::try_for_each) method. -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct TryForEach { - #[pin] - stream: St, - f: F, - #[pin] - future: Option, +pin_project! { + /// Future for the [`try_for_each`](super::TryStreamExt::try_for_each) method. + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct TryForEach { + #[pin] + stream: St, + f: F, + #[pin] + future: Option, + } } impl fmt::Debug for TryForEach diff --git a/futures-util/src/stream/try_stream/try_for_each_concurrent.rs b/futures-util/src/stream/try_stream/try_for_each_concurrent.rs index ee3af8c52d..d2f4b0fed2 100644 --- a/futures-util/src/stream/try_stream/try_for_each_concurrent.rs +++ b/futures-util/src/stream/try_stream/try_for_each_concurrent.rs @@ -6,19 +6,20 @@ use core::num::NonZeroUsize; use futures_core::future::{FusedFuture, Future}; use futures_core::stream::TryStream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Future for the -/// [`try_for_each_concurrent`](super::TryStreamExt::try_for_each_concurrent) -/// method. -#[pin_project] -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct TryForEachConcurrent { - #[pin] - stream: Option, - f: F, - futures: FuturesUnordered, - limit: Option, +pin_project! { + /// Future for the + /// [`try_for_each_concurrent`](super::TryStreamExt::try_for_each_concurrent) + /// method. + #[must_use = "futures do nothing unless you `.await` or poll them"] + pub struct TryForEachConcurrent { + #[pin] + stream: Option, + f: F, + futures: FuturesUnordered, + limit: Option, + } } impl fmt::Debug for TryForEachConcurrent diff --git a/futures-util/src/stream/try_stream/try_skip_while.rs b/futures-util/src/stream/try_stream/try_skip_while.rs index b25ede455d..0603b10f85 100644 --- a/futures-util/src/stream/try_stream/try_skip_while.rs +++ b/futures-util/src/stream/try_stream/try_skip_while.rs @@ -6,20 +6,21 @@ use futures_core::stream::{Stream, TryStream, FusedStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`try_skip_while`](super::TryStreamExt::try_skip_while) -/// method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TrySkipWhile where St: TryStream { - #[pin] - stream: St, - f: F, - #[pin] - pending_fut: Option, - pending_item: Option, - done_skipping: bool, +pin_project! { + /// Stream for the [`try_skip_while`](super::TryStreamExt::try_skip_while) + /// method. + #[must_use = "streams do nothing unless polled"] + pub struct TrySkipWhile where St: TryStream { + #[pin] + stream: St, + f: F, + #[pin] + pending_fut: Option, + pending_item: Option, + done_skipping: bool, + } } impl fmt::Debug for TrySkipWhile diff --git a/futures-util/src/stream/try_stream/try_take_while.rs b/futures-util/src/stream/try_stream/try_take_while.rs index ea85279804..624157290c 100644 --- a/futures-util/src/stream/try_stream/try_take_while.rs +++ b/futures-util/src/stream/try_stream/try_take_while.rs @@ -6,23 +6,24 @@ use futures_core::stream::{FusedStream, Stream, TryStream}; use futures_core::task::{Context, Poll}; #[cfg(feature = "sink")] use futures_sink::Sink; -use pin_project::pin_project; +use pin_project_lite::pin_project; -/// Stream for the [`try_take_while`](super::TryStreamExt::try_take_while) -/// method. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TryTakeWhile -where - St: TryStream, -{ - #[pin] - stream: St, - f: F, - #[pin] - pending_fut: Option, - pending_item: Option, - done_taking: bool, +pin_project! { + /// Stream for the [`try_take_while`](super::TryStreamExt::try_take_while) + /// method. + #[must_use = "streams do nothing unless polled"] + pub struct TryTakeWhile + where + St: TryStream, + { + #[pin] + stream: St, + f: F, + #[pin] + pending_fut: Option, + pending_item: Option, + done_taking: bool, + } } impl fmt::Debug for TryTakeWhile diff --git a/futures-util/src/stream/try_stream/try_unfold.rs b/futures-util/src/stream/try_stream/try_unfold.rs index e337548b04..c8fc421386 100644 --- a/futures-util/src/stream/try_stream/try_unfold.rs +++ b/futures-util/src/stream/try_stream/try_unfold.rs @@ -4,7 +4,7 @@ use futures_core::future::TryFuture; use futures_core::ready; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; /// Creates a `TryStream` from a seed and a closure returning a `TryFuture`. /// @@ -67,14 +67,15 @@ where } } -/// Stream for the [`try_unfold`] function. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct TryUnfold { - f: F, - state: Option, - #[pin] - fut: Option, +pin_project! { + /// Stream for the [`try_unfold`] function. + #[must_use = "streams do nothing unless polled"] + pub struct TryUnfold { + f: F, + state: Option, + #[pin] + fut: Option, + } } impl fmt::Debug for TryUnfold diff --git a/futures-util/src/stream/unfold.rs b/futures-util/src/stream/unfold.rs index e3401375ab..7149f3e7e1 100644 --- a/futures-util/src/stream/unfold.rs +++ b/futures-util/src/stream/unfold.rs @@ -4,7 +4,7 @@ use futures_core::future::Future; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; -use pin_project::pin_project; +use pin_project_lite::pin_project; /// Creates a `Stream` from a seed and a closure returning a `Future`. /// @@ -56,14 +56,15 @@ pub fn unfold(init: T, f: F) -> Unfold } } -/// Stream for the [`unfold`] function. -#[pin_project] -#[must_use = "streams do nothing unless polled"] -pub struct Unfold { - f: F, - state: Option, - #[pin] - fut: Option, +pin_project! { + /// Stream for the [`unfold`] function. + #[must_use = "streams do nothing unless polled"] + pub struct Unfold { + f: F, + state: Option, + #[pin] + fut: Option, + } } impl fmt::Debug for Unfold