From 58f4642eae6aa4f3e0be5f2f26fd72f23761a73b Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 10 Jan 2020 17:13:09 +0100 Subject: [PATCH 1/4] attempt to fix Send guards on collect Signed-off-by: Yoshua Wuyts --- src/collections/binary_heap/from_stream.rs | 2 +- src/collections/btree_map/from_stream.rs | 2 +- src/collections/btree_set/from_stream.rs | 2 +- src/collections/hash_map/from_stream.rs | 3 ++- src/collections/hash_set/from_stream.rs | 2 +- src/collections/linked_list/from_stream.rs | 2 +- src/collections/vec_deque/from_stream.rs | 2 +- src/option/from_stream.rs | 2 +- src/path/pathbuf.rs | 2 +- src/result/from_stream.rs | 2 ++ src/stream/from_stream.rs | 4 ++-- src/stream/stream/mod.rs | 1 + src/vec/from_stream.rs | 10 +++++----- tests/collect.rs | 18 ++++++++++++++++++ 14 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 tests/collect.rs diff --git a/src/collections/binary_heap/from_stream.rs b/src/collections/binary_heap/from_stream.rs index 6851948e6..80022d28a 100644 --- a/src/collections/binary_heap/from_stream.rs +++ b/src/collections/binary_heap/from_stream.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; -impl FromStream for BinaryHeap { +impl FromStream for BinaryHeap { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/src/collections/btree_map/from_stream.rs b/src/collections/btree_map/from_stream.rs index 853122361..d1b6ca20a 100644 --- a/src/collections/btree_map/from_stream.rs +++ b/src/collections/btree_map/from_stream.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; -impl FromStream<(K, V)> for BTreeMap { +impl FromStream<(K, V)> for BTreeMap { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/src/collections/btree_set/from_stream.rs b/src/collections/btree_set/from_stream.rs index 318af9e65..e943c2731 100644 --- a/src/collections/btree_set/from_stream.rs +++ b/src/collections/btree_set/from_stream.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; -impl FromStream for BTreeSet { +impl FromStream for BTreeSet { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/src/collections/hash_map/from_stream.rs b/src/collections/hash_map/from_stream.rs index d74a7ccfa..40b86f0fe 100644 --- a/src/collections/hash_map/from_stream.rs +++ b/src/collections/hash_map/from_stream.rs @@ -7,8 +7,9 @@ use crate::stream::{self, FromStream, IntoStream}; impl FromStream<(K, V)> for HashMap where - K: Eq + Hash, + K: Eq + Hash + Send, H: BuildHasher + Default, + V: Send, { #[inline] fn from_stream<'a, S: IntoStream + 'a>( diff --git a/src/collections/hash_set/from_stream.rs b/src/collections/hash_set/from_stream.rs index dc5e61e39..e0ca39206 100644 --- a/src/collections/hash_set/from_stream.rs +++ b/src/collections/hash_set/from_stream.rs @@ -7,7 +7,7 @@ use crate::stream::{self, FromStream, IntoStream}; impl FromStream for HashSet where - T: Eq + Hash, + T: Eq + Hash + Send, H: BuildHasher + Default, { #[inline] diff --git a/src/collections/linked_list/from_stream.rs b/src/collections/linked_list/from_stream.rs index d93bbb7be..972b39d6f 100644 --- a/src/collections/linked_list/from_stream.rs +++ b/src/collections/linked_list/from_stream.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; -impl FromStream for LinkedList { +impl FromStream for LinkedList { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/src/collections/vec_deque/from_stream.rs b/src/collections/vec_deque/from_stream.rs index 241bd74e9..540665705 100644 --- a/src/collections/vec_deque/from_stream.rs +++ b/src/collections/vec_deque/from_stream.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; -impl FromStream for VecDeque { +impl FromStream for VecDeque { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/src/option/from_stream.rs b/src/option/from_stream.rs index de929ca94..90be98b7a 100644 --- a/src/option/from_stream.rs +++ b/src/option/from_stream.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use crate::stream::{FromStream, IntoStream}; use std::convert::identity; -impl FromStream> for Option +impl FromStream> for Option where V: FromStream, { diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index e684df89f..1e42693c8 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -337,7 +337,7 @@ impl> stream::Extend

for PathBuf { } #[cfg(feature = "unstable")] -impl<'b, P: AsRef + 'b> FromStream

for PathBuf { +impl<'b, P: AsRef + 'b + Send> FromStream

for PathBuf { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/src/result/from_stream.rs b/src/result/from_stream.rs index 8a8e0eaf3..50d8bedbd 100644 --- a/src/result/from_stream.rs +++ b/src/result/from_stream.rs @@ -5,6 +5,8 @@ use crate::stream::{FromStream, IntoStream}; impl FromStream> for Result where + T: Send, + E: Send, V: FromStream, { /// Takes each element in the stream: if it is an `Err`, no further diff --git a/src/stream/from_stream.rs b/src/stream/from_stream.rs index 12d89e813..9507309e6 100644 --- a/src/stream/from_stream.rs +++ b/src/stream/from_stream.rs @@ -107,12 +107,12 @@ use crate::stream::IntoStream; /// assert_eq!(c.0, vec![5, 5, 5, 5, 5]); /// # /// # Ok(()) }) } -///``` +/// ``` /// /// [`IntoStream`]: trait.IntoStream.html #[cfg(feature = "unstable")] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] -pub trait FromStream { +pub trait FromStream { /// Creates a value from a stream. /// /// # Examples diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 4be0eb5f9..42afe9e45 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -1892,6 +1892,7 @@ extension_trait! { where Self: Sized + 'a, B: FromStream, + Self::Item: Send, { FromStream::from_stream(self) } diff --git a/src/vec/from_stream.rs b/src/vec/from_stream.rs index e88e8202e..2b1c31e03 100644 --- a/src/vec/from_stream.rs +++ b/src/vec/from_stream.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use crate::prelude::*; use crate::stream::{self, FromStream, IntoStream}; -impl FromStream for Vec { +impl FromStream for Vec { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, @@ -24,7 +24,7 @@ impl FromStream for Vec { } } -impl<'b, T: Clone> FromStream for Cow<'b, [T]> { +impl<'b, T: Clone + Send> FromStream for Cow<'b, [T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, @@ -37,7 +37,7 @@ impl<'b, T: Clone> FromStream for Cow<'b, [T]> { } } -impl FromStream for Box<[T]> { +impl FromStream for Box<[T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, @@ -50,7 +50,7 @@ impl FromStream for Box<[T]> { } } -impl FromStream for Rc<[T]> { +impl FromStream for Rc<[T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, @@ -63,7 +63,7 @@ impl FromStream for Rc<[T]> { } } -impl FromStream for Arc<[T]> { +impl FromStream for Arc<[T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, diff --git a/tests/collect.rs b/tests/collect.rs new file mode 100644 index 000000000..82d2f8083 --- /dev/null +++ b/tests/collect.rs @@ -0,0 +1,18 @@ +use async_std::prelude::*; +use async_std::io; +use async_std::task; + +#[test] +fn test_send() -> io::Result<()> { + task::block_on(async { + fn test_send_trait(_: &T) {} + + let stream = futures::stream::pending::<()>(); + test_send_trait(&stream); + + let fut = stream.collect::>(); + + // This line triggers a compilation error + test_send_trait(&fut); + }) +} From c6836ec4750a1679d4d5c23f8ae178fc5ca2e78e Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sat, 27 Jun 2020 14:45:59 +0200 Subject: [PATCH 2/4] fixup test --- tests/collect.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/collect.rs b/tests/collect.rs index 82d2f8083..d24484f4e 100644 --- a/tests/collect.rs +++ b/tests/collect.rs @@ -1,18 +1,20 @@ -use async_std::prelude::*; -use async_std::io; -use async_std::task; - +#[cfg(feature = "unstable")] #[test] -fn test_send() -> io::Result<()> { +fn test_send() -> async_std::io::Result<()> { + use async_std::prelude::*; + use async_std::{stream, task}; + task::block_on(async { fn test_send_trait(_: &T) {} - let stream = futures::stream::pending::<()>(); + let stream = stream::repeat(1u8).take(10); test_send_trait(&stream); let fut = stream.collect::>(); // This line triggers a compilation error test_send_trait(&fut); + + Ok(()) }) } From 9cb2a764d90bbb1d99ac2d16402c3d3ddc89d25a Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sat, 27 Jun 2020 16:11:12 +0200 Subject: [PATCH 3/4] first compiling version --- src/collections/binary_heap/extend.rs | 9 ++++-- src/collections/binary_heap/from_stream.rs | 5 +++- src/collections/btree_map/extend.rs | 9 ++++-- src/collections/btree_map/from_stream.rs | 5 +++- src/collections/btree_set/extend.rs | 9 ++++-- src/collections/btree_set/from_stream.rs | 5 +++- src/collections/hash_map/extend.rs | 12 +++++--- src/collections/hash_map/from_stream.rs | 7 +++-- src/collections/hash_set/extend.rs | 11 ++++--- src/collections/hash_set/from_stream.rs | 7 +++-- src/collections/linked_list/extend.rs | 9 ++++-- src/collections/linked_list/from_stream.rs | 5 +++- src/collections/vec_deque/extend.rs | 9 ++++-- src/collections/vec_deque/from_stream.rs | 5 +++- src/option/from_stream.rs | 5 +++- src/path/pathbuf.rs | 12 ++++++-- src/result/from_stream.rs | 5 +++- src/stream/extend.rs | 9 ++++-- src/stream/from_stream.rs | 9 ++++-- src/stream/stream/mod.rs | 4 +-- src/string/extend.rs | 35 +++++++++++++++------- src/string/from_stream.rs | 25 ++++++++++++---- src/unit/extend.rs | 9 ++++-- src/unit/from_stream.rs | 5 +++- src/vec/extend.rs | 9 ++++-- src/vec/from_stream.rs | 24 +++++++++++---- 26 files changed, 186 insertions(+), 72 deletions(-) diff --git a/src/collections/binary_heap/extend.rs b/src/collections/binary_heap/extend.rs index 439bf139e..64fe88c2a 100644 --- a/src/collections/binary_heap/extend.rs +++ b/src/collections/binary_heap/extend.rs @@ -4,11 +4,14 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, IntoStream}; -impl stream::Extend for BinaryHeap { - fn extend<'a, S: IntoStream + 'a>( +impl stream::Extend for BinaryHeap { + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); self.reserve(stream.size_hint().0); diff --git a/src/collections/binary_heap/from_stream.rs b/src/collections/binary_heap/from_stream.rs index 80022d28a..614f5f5de 100644 --- a/src/collections/binary_heap/from_stream.rs +++ b/src/collections/binary_heap/from_stream.rs @@ -8,7 +8,10 @@ impl FromStream for BinaryHeap { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/btree_map/extend.rs b/src/collections/btree_map/extend.rs index 19d306ffe..69189f7a3 100644 --- a/src/collections/btree_map/extend.rs +++ b/src/collections/btree_map/extend.rs @@ -4,11 +4,14 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, IntoStream}; -impl stream::Extend<(K, V)> for BTreeMap { - fn extend<'a, S: IntoStream + 'a>( +impl stream::Extend<(K, V)> for BTreeMap { + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { Box::pin(stream.into_stream().for_each(move |(k, v)| { self.insert(k, v); })) diff --git a/src/collections/btree_map/from_stream.rs b/src/collections/btree_map/from_stream.rs index d1b6ca20a..ef01b6e0d 100644 --- a/src/collections/btree_map/from_stream.rs +++ b/src/collections/btree_map/from_stream.rs @@ -8,7 +8,10 @@ impl FromStream<(K, V)> for BTreeMap { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/btree_set/extend.rs b/src/collections/btree_set/extend.rs index 422640b15..4222ae7d7 100644 --- a/src/collections/btree_set/extend.rs +++ b/src/collections/btree_set/extend.rs @@ -4,11 +4,14 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, IntoStream}; -impl stream::Extend for BTreeSet { - fn extend<'a, S: IntoStream + 'a>( +impl stream::Extend for BTreeSet { + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { Box::pin(stream.into_stream().for_each(move |item| { self.insert(item); })) diff --git a/src/collections/btree_set/from_stream.rs b/src/collections/btree_set/from_stream.rs index e943c2731..5fdb33e6c 100644 --- a/src/collections/btree_set/from_stream.rs +++ b/src/collections/btree_set/from_stream.rs @@ -8,7 +8,10 @@ impl FromStream for BTreeSet { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/hash_map/extend.rs b/src/collections/hash_map/extend.rs index 0f4ce0c6e..b0b2e494b 100644 --- a/src/collections/hash_map/extend.rs +++ b/src/collections/hash_map/extend.rs @@ -7,13 +7,17 @@ use crate::stream::{self, IntoStream}; impl stream::Extend<(K, V)> for HashMap where - K: Eq + Hash, - H: BuildHasher + Default, + K: Eq + Hash + Send, + V: Send, + H: BuildHasher + Default + Send, { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); // The following is adapted from the hashbrown source code: diff --git a/src/collections/hash_map/from_stream.rs b/src/collections/hash_map/from_stream.rs index 40b86f0fe..ae3f11a56 100644 --- a/src/collections/hash_map/from_stream.rs +++ b/src/collections/hash_map/from_stream.rs @@ -8,13 +8,16 @@ use crate::stream::{self, FromStream, IntoStream}; impl FromStream<(K, V)> for HashMap where K: Eq + Hash + Send, - H: BuildHasher + Default, + H: BuildHasher + Default + Send, V: Send, { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/hash_set/extend.rs b/src/collections/hash_set/extend.rs index ba872b438..15429d358 100644 --- a/src/collections/hash_set/extend.rs +++ b/src/collections/hash_set/extend.rs @@ -7,13 +7,16 @@ use crate::stream::{self, IntoStream}; impl stream::Extend for HashSet where - T: Eq + Hash, - H: BuildHasher + Default, + T: Eq + Hash + Send, + H: BuildHasher + Default + Send, { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { // The Extend impl for HashSet in the standard library delegates to the internal HashMap. // Thus, this impl is just a copy of the async Extend impl for HashMap in this crate. diff --git a/src/collections/hash_set/from_stream.rs b/src/collections/hash_set/from_stream.rs index e0ca39206..6f640695a 100644 --- a/src/collections/hash_set/from_stream.rs +++ b/src/collections/hash_set/from_stream.rs @@ -8,12 +8,15 @@ use crate::stream::{self, FromStream, IntoStream}; impl FromStream for HashSet where T: Eq + Hash + Send, - H: BuildHasher + Default, + H: BuildHasher + Default + Send, { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/linked_list/extend.rs b/src/collections/linked_list/extend.rs index b0dff009d..39dffbe46 100644 --- a/src/collections/linked_list/extend.rs +++ b/src/collections/linked_list/extend.rs @@ -4,11 +4,14 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, IntoStream}; -impl stream::Extend for LinkedList { - fn extend<'a, S: IntoStream + 'a>( +impl stream::Extend for LinkedList { + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(stream.for_each(move |item| self.push_back(item))) } diff --git a/src/collections/linked_list/from_stream.rs b/src/collections/linked_list/from_stream.rs index 972b39d6f..7c3eb738c 100644 --- a/src/collections/linked_list/from_stream.rs +++ b/src/collections/linked_list/from_stream.rs @@ -8,7 +8,10 @@ impl FromStream for LinkedList { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/collections/vec_deque/extend.rs b/src/collections/vec_deque/extend.rs index dd2ddce3c..a642313be 100644 --- a/src/collections/vec_deque/extend.rs +++ b/src/collections/vec_deque/extend.rs @@ -4,11 +4,14 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, IntoStream}; -impl stream::Extend for VecDeque { - fn extend<'a, S: IntoStream + 'a>( +impl stream::Extend for VecDeque { + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); self.reserve(stream.size_hint().0); diff --git a/src/collections/vec_deque/from_stream.rs b/src/collections/vec_deque/from_stream.rs index 540665705..3e0719ab2 100644 --- a/src/collections/vec_deque/from_stream.rs +++ b/src/collections/vec_deque/from_stream.rs @@ -8,7 +8,10 @@ impl FromStream for VecDeque { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/option/from_stream.rs b/src/option/from_stream.rs index 90be98b7a..7931d97a6 100644 --- a/src/option/from_stream.rs +++ b/src/option/from_stream.rs @@ -14,7 +14,10 @@ where #[inline] fn from_stream<'a, S: IntoStream> + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index 1e42693c8..b673f1741 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -320,10 +320,13 @@ impl AsRef for PathBuf { #[cfg(feature = "unstable")] impl> stream::Extend

for PathBuf { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -341,7 +344,10 @@ impl<'b, P: AsRef + 'b + Send> FromStream

for PathBuf { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/result/from_stream.rs b/src/result/from_stream.rs index 50d8bedbd..68fa535fa 100644 --- a/src/result/from_stream.rs +++ b/src/result/from_stream.rs @@ -32,7 +32,10 @@ where #[inline] fn from_stream<'a, S: IntoStream> + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/stream/extend.rs b/src/stream/extend.rs index 702cbcac6..5f58dfe11 100644 --- a/src/stream/extend.rs +++ b/src/stream/extend.rs @@ -31,10 +31,12 @@ use crate::stream::IntoStream; #[cfg_attr(feature = "docs", doc(cfg(unstable)))] pub trait Extend { /// Extends a collection with the contents of a stream. - fn extend<'a, T: IntoStream + 'a>( + fn extend<'a, T: IntoStream + 'a + Send>( &'a mut self, stream: T, - ) -> Pin + 'a>>; + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send; } /// Extends a collection with the contents of a stream. @@ -68,7 +70,8 @@ pub trait Extend { pub async fn extend<'a, C, T, S>(collection: &mut C, stream: S) where C: Extend, - S: IntoStream + 'a, + S: IntoStream + 'a + Send, + ::IntoStream: Send, { Extend::extend(collection, stream).await } diff --git a/src/stream/from_stream.rs b/src/stream/from_stream.rs index 9507309e6..c4001917c 100644 --- a/src/stream/from_stream.rs +++ b/src/stream/from_stream.rs @@ -72,7 +72,10 @@ use crate::stream::IntoStream; /// impl FromStream for MyCollection { /// fn from_stream<'a, S: IntoStream + 'a>( /// stream: S, -/// ) -> Pin + 'a>> { +/// ) -> Pin + 'a + Send>> +/// where +/// ::IntoStream: Send, +/// { /// let stream = stream.into_stream(); /// /// Box::pin(async move { @@ -135,5 +138,7 @@ pub trait FromStream { /// ``` fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>>; + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send; } diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 42afe9e45..4e074a2f3 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -1888,9 +1888,9 @@ extension_trait! { #[cfg_attr(feature = "docs", doc(cfg(unstable)))] fn collect<'a, B>( self, - ) -> impl Future + 'a [Pin + 'a>>] + ) -> impl Future + 'a [Pin + 'a + Send>>] where - Self: Sized + 'a, + Self: Sized + 'a + Send, B: FromStream, Self::Item: Send, { diff --git a/src/string/extend.rs b/src/string/extend.rs index 55bec0c55..6b06c9352 100644 --- a/src/string/extend.rs +++ b/src/string/extend.rs @@ -5,10 +5,13 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for String { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); self.reserve(stream.size_hint().0); @@ -23,10 +26,13 @@ impl stream::Extend for String { } impl<'b> stream::Extend<&'b char> for String { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -40,10 +46,13 @@ impl<'b> stream::Extend<&'b char> for String { } impl<'b> stream::Extend<&'b str> for String { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -57,10 +66,13 @@ impl<'b> stream::Extend<&'b str> for String { } impl stream::Extend for String { - fn extend<'a, S: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -74,10 +86,13 @@ impl stream::Extend for String { } impl<'b> stream::Extend> for String { - fn extend<'a, S: IntoStream> + 'a>( + fn extend<'a, S: IntoStream> + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/string/from_stream.rs b/src/string/from_stream.rs index 375ac3715..d9e824681 100644 --- a/src/string/from_stream.rs +++ b/src/string/from_stream.rs @@ -8,7 +8,10 @@ impl FromStream for String { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -23,7 +26,10 @@ impl<'b> FromStream<&'b char> for String { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -38,7 +44,10 @@ impl<'b> FromStream<&'b str> for String { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -53,7 +62,10 @@ impl FromStream for String { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { @@ -68,7 +80,10 @@ impl<'b> FromStream> for String { #[inline] fn from_stream<'a, S: IntoStream> + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/unit/extend.rs b/src/unit/extend.rs index 55c8e0d08..8f42eb5b7 100644 --- a/src/unit/extend.rs +++ b/src/unit/extend.rs @@ -4,10 +4,13 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend<()> for () { - fn extend<'a, T: IntoStream + 'a>( + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, - stream: T, - ) -> Pin + 'a>> { + stream: S, + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); Box::pin(async move { diff --git a/src/unit/from_stream.rs b/src/unit/from_stream.rs index 7b784383d..e88758323 100644 --- a/src/unit/from_stream.rs +++ b/src/unit/from_stream.rs @@ -7,7 +7,10 @@ impl FromStream<()> for () { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { Box::pin(stream.into_stream().for_each(drop)) } } diff --git a/src/vec/extend.rs b/src/vec/extend.rs index 302fc7a87..8ec00ef86 100644 --- a/src/vec/extend.rs +++ b/src/vec/extend.rs @@ -3,11 +3,14 @@ use std::pin::Pin; use crate::prelude::*; use crate::stream::{self, IntoStream}; -impl stream::Extend for Vec { - fn extend<'a, S: IntoStream + 'a>( +impl stream::Extend for Vec { + fn extend<'a, S: IntoStream + 'a + Send>( &'a mut self, stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send, + { let stream = stream.into_stream(); self.reserve(stream.size_hint().0); diff --git a/src/vec/from_stream.rs b/src/vec/from_stream.rs index 2b1c31e03..95a1f98c9 100644 --- a/src/vec/from_stream.rs +++ b/src/vec/from_stream.rs @@ -10,9 +10,9 @@ impl FromStream for Vec { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, - ) -> Pin + 'a>> + ) -> Pin + 'a + Send>> where - ::IntoStream: 'a, + ::IntoStream: 'a + Send, { let stream = stream.into_stream(); @@ -28,7 +28,10 @@ impl<'b, T: Clone + Send> FromStream for Cow<'b, [T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send + { let stream = stream.into_stream(); Box::pin(async move { @@ -41,7 +44,10 @@ impl FromStream for Box<[T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send + { let stream = stream.into_stream(); Box::pin(async move { @@ -54,7 +60,10 @@ impl FromStream for Rc<[T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send + { let stream = stream.into_stream(); Box::pin(async move { @@ -67,7 +76,10 @@ impl FromStream for Arc<[T]> { #[inline] fn from_stream<'a, S: IntoStream + 'a>( stream: S, - ) -> Pin + 'a>> { + ) -> Pin + 'a + Send>> + where + ::IntoStream: Send + { let stream = stream.into_stream(); Box::pin(async move { From 656eb010e6bc6757c629304a133111c150fdcf97 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sat, 27 Jun 2020 16:13:45 +0200 Subject: [PATCH 4/4] simplify trait bound --- src/collections/binary_heap/extend.rs | 2 +- src/collections/btree_map/extend.rs | 2 +- src/collections/btree_set/extend.rs | 2 +- src/collections/hash_map/extend.rs | 2 +- src/collections/hash_set/extend.rs | 2 +- src/collections/linked_list/extend.rs | 2 +- src/collections/vec_deque/extend.rs | 2 +- src/path/pathbuf.rs | 2 +- src/stream/extend.rs | 4 ++-- src/string/extend.rs | 10 +++++----- src/unit/extend.rs | 2 +- src/vec/extend.rs | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/collections/binary_heap/extend.rs b/src/collections/binary_heap/extend.rs index 64fe88c2a..1a9479e14 100644 --- a/src/collections/binary_heap/extend.rs +++ b/src/collections/binary_heap/extend.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for BinaryHeap { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/collections/btree_map/extend.rs b/src/collections/btree_map/extend.rs index 69189f7a3..4a1ad0618 100644 --- a/src/collections/btree_map/extend.rs +++ b/src/collections/btree_map/extend.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend<(K, V)> for BTreeMap { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/collections/btree_set/extend.rs b/src/collections/btree_set/extend.rs index 4222ae7d7..0f7421023 100644 --- a/src/collections/btree_set/extend.rs +++ b/src/collections/btree_set/extend.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for BTreeSet { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/collections/hash_map/extend.rs b/src/collections/hash_map/extend.rs index b0b2e494b..15b7e7d46 100644 --- a/src/collections/hash_map/extend.rs +++ b/src/collections/hash_map/extend.rs @@ -11,7 +11,7 @@ where V: Send, H: BuildHasher + Default + Send, { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/collections/hash_set/extend.rs b/src/collections/hash_set/extend.rs index 15429d358..0246a1e88 100644 --- a/src/collections/hash_set/extend.rs +++ b/src/collections/hash_set/extend.rs @@ -10,7 +10,7 @@ where T: Eq + Hash + Send, H: BuildHasher + Default + Send, { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/collections/linked_list/extend.rs b/src/collections/linked_list/extend.rs index 39dffbe46..8adc41d73 100644 --- a/src/collections/linked_list/extend.rs +++ b/src/collections/linked_list/extend.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for LinkedList { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/collections/vec_deque/extend.rs b/src/collections/vec_deque/extend.rs index a642313be..9dea92231 100644 --- a/src/collections/vec_deque/extend.rs +++ b/src/collections/vec_deque/extend.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for VecDeque { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index b673f1741..f9370cbab 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -320,7 +320,7 @@ impl AsRef for PathBuf { #[cfg(feature = "unstable")] impl> stream::Extend

for PathBuf { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/stream/extend.rs b/src/stream/extend.rs index 5f58dfe11..0c7d41049 100644 --- a/src/stream/extend.rs +++ b/src/stream/extend.rs @@ -31,7 +31,7 @@ use crate::stream::IntoStream; #[cfg_attr(feature = "docs", doc(cfg(unstable)))] pub trait Extend { /// Extends a collection with the contents of a stream. - fn extend<'a, T: IntoStream + 'a + Send>( + fn extend<'a, T: IntoStream + 'a>( &'a mut self, stream: T, ) -> Pin + 'a + Send>> @@ -70,7 +70,7 @@ pub trait Extend { pub async fn extend<'a, C, T, S>(collection: &mut C, stream: S) where C: Extend, - S: IntoStream + 'a + Send, + S: IntoStream + 'a, ::IntoStream: Send, { Extend::extend(collection, stream).await diff --git a/src/string/extend.rs b/src/string/extend.rs index 6b06c9352..eae824cbd 100644 --- a/src/string/extend.rs +++ b/src/string/extend.rs @@ -5,7 +5,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for String { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> @@ -26,7 +26,7 @@ impl stream::Extend for String { } impl<'b> stream::Extend<&'b char> for String { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> @@ -46,7 +46,7 @@ impl<'b> stream::Extend<&'b char> for String { } impl<'b> stream::Extend<&'b str> for String { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> @@ -66,7 +66,7 @@ impl<'b> stream::Extend<&'b str> for String { } impl stream::Extend for String { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> @@ -86,7 +86,7 @@ impl stream::Extend for String { } impl<'b> stream::Extend> for String { - fn extend<'a, S: IntoStream> + 'a + Send>( + fn extend<'a, S: IntoStream> + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/unit/extend.rs b/src/unit/extend.rs index 8f42eb5b7..ffc0c2d9d 100644 --- a/src/unit/extend.rs +++ b/src/unit/extend.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend<()> for () { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>> diff --git a/src/vec/extend.rs b/src/vec/extend.rs index 8ec00ef86..717338ab7 100644 --- a/src/vec/extend.rs +++ b/src/vec/extend.rs @@ -4,7 +4,7 @@ use crate::prelude::*; use crate::stream::{self, IntoStream}; impl stream::Extend for Vec { - fn extend<'a, S: IntoStream + 'a + Send>( + fn extend<'a, S: IntoStream + 'a>( &'a mut self, stream: S, ) -> Pin + 'a + Send>>