Skip to content

Commit c82b1ef

Browse files
fix(stream): add send guards on collect
Closes #639 Co-authored-by: dignifiedquire <me@dignifiedquire.com>
1 parent 8c4b425 commit c82b1ef

File tree

27 files changed

+210
-72
lines changed

27 files changed

+210
-72
lines changed

src/collections/binary_heap/extend.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, IntoStream};
66

7-
impl<T: Ord> stream::Extend<T> for BinaryHeap<T> {
7+
impl<T: Ord + Send> stream::Extend<T> for BinaryHeap<T> {
88
fn extend<'a, S: IntoStream<Item = T> + 'a>(
99
&'a mut self,
1010
stream: S,
11-
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
11+
) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>>
12+
where
13+
<S as IntoStream>::IntoStream: Send,
14+
{
1215
let stream = stream.into_stream();
1316

1417
self.reserve(stream.size_hint().0);

src/collections/binary_heap/from_stream.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, FromStream, IntoStream};
66

7-
impl<T: Ord> FromStream<T> for BinaryHeap<T> {
7+
impl<T: Ord + Send> FromStream<T> for BinaryHeap<T> {
88
#[inline]
99
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
1010
stream: S,
11-
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
11+
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
12+
where
13+
<S as IntoStream>::IntoStream: Send,
14+
{
1215
let stream = stream.into_stream();
1316

1417
Box::pin(async move {

src/collections/btree_map/extend.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, IntoStream};
66

7-
impl<K: Ord, V> stream::Extend<(K, V)> for BTreeMap<K, V> {
7+
impl<K: Ord + Send, V: Send> stream::Extend<(K, V)> for BTreeMap<K, V> {
88
fn extend<'a, S: IntoStream<Item = (K, V)> + 'a>(
99
&'a mut self,
1010
stream: S,
11-
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
11+
) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>>
12+
where
13+
<S as IntoStream>::IntoStream: Send,
14+
{
1215
Box::pin(stream.into_stream().for_each(move |(k, v)| {
1316
self.insert(k, v);
1417
}))

src/collections/btree_map/from_stream.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, FromStream, IntoStream};
66

7-
impl<K: Ord, V> FromStream<(K, V)> for BTreeMap<K, V> {
7+
impl<K: Ord + Send, V: Send> FromStream<(K, V)> for BTreeMap<K, V> {
88
#[inline]
99
fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(
1010
stream: S,
11-
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
11+
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
12+
where
13+
<S as IntoStream>::IntoStream: Send,
14+
{
1215
let stream = stream.into_stream();
1316

1417
Box::pin(async move {

src/collections/btree_set/extend.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, IntoStream};
66

7-
impl<T: Ord> stream::Extend<T> for BTreeSet<T> {
7+
impl<T: Ord + Send> stream::Extend<T> for BTreeSet<T> {
88
fn extend<'a, S: IntoStream<Item = T> + 'a>(
99
&'a mut self,
1010
stream: S,
11-
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
11+
) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>>
12+
where
13+
<S as IntoStream>::IntoStream: Send,
14+
{
1215
Box::pin(stream.into_stream().for_each(move |item| {
1316
self.insert(item);
1417
}))

src/collections/btree_set/from_stream.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, FromStream, IntoStream};
66

7-
impl<T: Ord> FromStream<T> for BTreeSet<T> {
7+
impl<T: Ord + Send> FromStream<T> for BTreeSet<T> {
88
#[inline]
99
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
1010
stream: S,
11-
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
11+
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
12+
where
13+
<S as IntoStream>::IntoStream: Send,
14+
{
1215
let stream = stream.into_stream();
1316

1417
Box::pin(async move {

src/collections/hash_map/extend.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ use crate::stream::{self, IntoStream};
77

88
impl<K, V, H> stream::Extend<(K, V)> for HashMap<K, V, H>
99
where
10-
K: Eq + Hash,
11-
H: BuildHasher + Default,
10+
K: Eq + Hash + Send,
11+
V: Send,
12+
H: BuildHasher + Default + Send,
1213
{
1314
fn extend<'a, S: IntoStream<Item = (K, V)> + 'a>(
1415
&'a mut self,
1516
stream: S,
16-
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
17+
) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>>
18+
where
19+
<S as IntoStream>::IntoStream: Send,
20+
{
1721
let stream = stream.into_stream();
1822

1923
// The following is adapted from the hashbrown source code:

src/collections/hash_map/from_stream.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ use crate::stream::{self, FromStream, IntoStream};
77

88
impl<K, V, H> FromStream<(K, V)> for HashMap<K, V, H>
99
where
10-
K: Eq + Hash,
11-
H: BuildHasher + Default,
10+
K: Eq + Hash + Send,
11+
H: BuildHasher + Default + Send,
12+
V: Send,
1213
{
1314
#[inline]
1415
fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(
1516
stream: S,
16-
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
17+
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
18+
where
19+
<S as IntoStream>::IntoStream: Send,
20+
{
1721
let stream = stream.into_stream();
1822

1923
Box::pin(async move {

src/collections/hash_set/extend.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ use crate::stream::{self, IntoStream};
77

88
impl<T, H> stream::Extend<T> for HashSet<T, H>
99
where
10-
T: Eq + Hash,
11-
H: BuildHasher + Default,
10+
T: Eq + Hash + Send,
11+
H: BuildHasher + Default + Send,
1212
{
1313
fn extend<'a, S: IntoStream<Item = T> + 'a>(
1414
&'a mut self,
1515
stream: S,
16-
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
16+
) -> Pin<Box<dyn Future<Output = ()> + 'a + Send>>
17+
where
18+
<S as IntoStream>::IntoStream: Send,
19+
{
1720
// The Extend impl for HashSet in the standard library delegates to the internal HashMap.
1821
// Thus, this impl is just a copy of the async Extend impl for HashMap in this crate.
1922

src/collections/hash_set/from_stream.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ use crate::stream::{self, FromStream, IntoStream};
77

88
impl<T, H> FromStream<T> for HashSet<T, H>
99
where
10-
T: Eq + Hash,
11-
H: BuildHasher + Default,
10+
T: Eq + Hash + Send,
11+
H: BuildHasher + Default + Send,
1212
{
1313
#[inline]
1414
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
1515
stream: S,
16-
) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
16+
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
17+
where
18+
<S as IntoStream>::IntoStream: Send,
19+
{
1720
let stream = stream.into_stream();
1821

1922
Box::pin(async move {

0 commit comments

Comments
 (0)