From e442eba625fb881dedc7572cf591e7f8b51ef0d0 Mon Sep 17 00:00:00 2001 From: Grzegorz Gierlach Date: Tue, 12 Nov 2019 19:51:58 +0100 Subject: [PATCH] Cleaning up stream pinning. --- src/path/pathbuf.rs | 2 ++ src/stream/from_fn.rs | 4 +++- src/stream/repeat_with.rs | 4 +++- src/string/extend.rs | 10 ++++++++++ src/unit/extend.rs | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index 808acb2..e684df8 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -327,6 +327,8 @@ impl> stream::Extend

for PathBuf { let stream = stream.into_stream(); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(item) = stream.next().await { self.push(item.as_ref()); } diff --git a/src/stream/from_fn.rs b/src/stream/from_fn.rs index 3ace658..8067176 100644 --- a/src/stream/from_fn.rs +++ b/src/stream/from_fn.rs @@ -30,7 +30,7 @@ impl Unpin for FromFn {} /// use async_std::stream; /// /// let mut count = 0u8; -/// let mut s = stream::from_fn(|| { +/// let s = stream::from_fn(|| { /// count += 1; /// if count > 3 { /// None @@ -39,6 +39,8 @@ impl Unpin for FromFn {} /// } /// }); /// +/// pin_utils::pin_mut!(s); +/// /// assert_eq!(s.next().await, Some(1)); /// assert_eq!(s.next().await, Some(2)); /// assert_eq!(s.next().await, Some(3)); diff --git a/src/stream/repeat_with.rs b/src/stream/repeat_with.rs index 954693d..e183a77 100644 --- a/src/stream/repeat_with.rs +++ b/src/stream/repeat_with.rs @@ -28,7 +28,9 @@ impl Unpin for RepeatWith {} /// use async_std::prelude::*; /// use async_std::stream; /// -/// let mut s = stream::repeat_with(|| 1); +/// let s = stream::repeat_with(|| 1); +/// +/// pin_utils::pin_mut!(s); /// /// assert_eq!(s.next().await, Some(1)); /// assert_eq!(s.next().await, Some(1)); diff --git a/src/string/extend.rs b/src/string/extend.rs index 43bd46d..55bec0c 100644 --- a/src/string/extend.rs +++ b/src/string/extend.rs @@ -13,6 +13,8 @@ impl stream::Extend for String { self.reserve(stream.size_hint().0); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(item) = stream.next().await { self.push(item); } @@ -28,6 +30,8 @@ impl<'b> stream::Extend<&'b char> for String { let stream = stream.into_stream(); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(item) = stream.next().await { self.push(*item); } @@ -43,6 +47,8 @@ impl<'b> stream::Extend<&'b str> for String { let stream = stream.into_stream(); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(item) = stream.next().await { self.push_str(item); } @@ -58,6 +64,8 @@ impl stream::Extend for String { let stream = stream.into_stream(); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(item) = stream.next().await { self.push_str(&item); } @@ -73,6 +81,8 @@ impl<'b> stream::Extend> for String { let stream = stream.into_stream(); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(item) = stream.next().await { self.push_str(&item); } diff --git a/src/unit/extend.rs b/src/unit/extend.rs index 5b0bc1d..55c8e0d 100644 --- a/src/unit/extend.rs +++ b/src/unit/extend.rs @@ -11,6 +11,8 @@ impl stream::Extend<()> for () { let stream = stream.into_stream(); Box::pin(async move { + pin_utils::pin_mut!(stream); + while let Some(_) = stream.next().await {} }) }