Skip to content

Commit c413fcb

Browse files
committed
attempt to fix Send guards on collect
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 1f78efe commit c413fcb

File tree

14 files changed

+38
-16
lines changed

14 files changed

+38
-16
lines changed

src/collections/binary_heap/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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,

src/collections/btree_map/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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,

src/collections/btree_set/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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,

src/collections/hash_map/from_stream.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ 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,
10+
K: Eq + Hash + Send,
1111
H: BuildHasher + Default,
12+
V: Send,
1213
{
1314
#[inline]
1415
fn from_stream<'a, S: IntoStream<Item = (K, V)> + 'a>(

src/collections/hash_set/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::stream::{self, FromStream, IntoStream};
77

88
impl<T, H> FromStream<T> for HashSet<T, H>
99
where
10-
T: Eq + Hash,
10+
T: Eq + Hash + Send,
1111
H: BuildHasher + Default,
1212
{
1313
#[inline]

src/collections/linked_list/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, FromStream, IntoStream};
66

7-
impl<T> FromStream<T> for LinkedList<T> {
7+
impl<T: Send> FromStream<T> for LinkedList<T> {
88
#[inline]
99
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
1010
stream: S,

src/collections/vec_deque/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::pin::Pin;
44
use crate::prelude::*;
55
use crate::stream::{self, FromStream, IntoStream};
66

7-
impl<T> FromStream<T> for VecDeque<T> {
7+
impl<T: Send> FromStream<T> for VecDeque<T> {
88
#[inline]
99
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
1010
stream: S,

src/option/from_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::pin::Pin;
33
use crate::prelude::*;
44
use crate::stream::{FromStream, IntoStream};
55

6-
impl<T, V> FromStream<Option<T>> for Option<V>
6+
impl<T: Send, V> FromStream<Option<T>> for Option<V>
77
where
88
V: FromStream<T>,
99
{

src/path/pathbuf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<P: AsRef<Path>> stream::Extend<P> for PathBuf {
337337
}
338338

339339
#[cfg(feature = "unstable")]
340-
impl<'b, P: AsRef<Path> + 'b> FromStream<P> for PathBuf {
340+
impl<'b, P: AsRef<Path> + 'b + Send> FromStream<P> for PathBuf {
341341
#[inline]
342342
fn from_stream<'a, S: IntoStream<Item = P> + 'a>(
343343
stream: S,

src/result/from_stream.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::stream::{FromStream, IntoStream};
55

66
impl<T, E, V> FromStream<Result<T, E>> for Result<V, E>
77
where
8+
T: Send,
9+
E: Send,
810
V: FromStream<T>,
911
{
1012
/// Takes each element in the stream: if it is an `Err`, no further

src/stream/from_stream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ use crate::stream::IntoStream;
107107
/// assert_eq!(c.0, vec![5, 5, 5, 5, 5]);
108108
/// #
109109
/// # Ok(()) }) }
110-
///```
110+
/// ```
111111
///
112112
/// [`IntoStream`]: trait.IntoStream.html
113113
#[cfg(feature = "unstable")]
114114
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
115-
pub trait FromStream<T> {
115+
pub trait FromStream<T: Send> {
116116
/// Creates a value from a stream.
117117
///
118118
/// # Examples

src/stream/stream/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,7 @@ extension_trait! {
18811881
where
18821882
Self: Sized + 'a,
18831883
B: FromStream<Self::Item>,
1884+
Self::Item: Send,
18841885
{
18851886
FromStream::from_stream(self)
18861887
}

src/vec/from_stream.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use crate::prelude::*;
77
use crate::stream::{self, FromStream, IntoStream};
88

9-
impl<T> FromStream<T> for Vec<T> {
9+
impl<T: Send> FromStream<T> for Vec<T> {
1010
#[inline]
1111
fn from_stream<'a, S: IntoStream<Item = T>>(
1212
stream: S,
@@ -24,7 +24,7 @@ impl<T> FromStream<T> for Vec<T> {
2424
}
2525
}
2626

27-
impl<'b, T: Clone> FromStream<T> for Cow<'b, [T]> {
27+
impl<'b, T: Clone + Send> FromStream<T> for Cow<'b, [T]> {
2828
#[inline]
2929
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
3030
stream: S,
@@ -37,7 +37,7 @@ impl<'b, T: Clone> FromStream<T> for Cow<'b, [T]> {
3737
}
3838
}
3939

40-
impl<T> FromStream<T> for Box<[T]> {
40+
impl<T: Send> FromStream<T> for Box<[T]> {
4141
#[inline]
4242
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
4343
stream: S,
@@ -50,7 +50,7 @@ impl<T> FromStream<T> for Box<[T]> {
5050
}
5151
}
5252

53-
impl<T> FromStream<T> for Rc<[T]> {
53+
impl<T: Send> FromStream<T> for Rc<[T]> {
5454
#[inline]
5555
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
5656
stream: S,
@@ -63,7 +63,7 @@ impl<T> FromStream<T> for Rc<[T]> {
6363
}
6464
}
6565

66-
impl<T> FromStream<T> for Arc<[T]> {
66+
impl<T: Send> FromStream<T> for Arc<[T]> {
6767
#[inline]
6868
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
6969
stream: S,

tests/collect.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use async_std::prelude::*;
2+
use async_std::io;
3+
use async_std::task;
4+
5+
#[test]
6+
fn test_send() -> io::Result<()> {
7+
task::block_on(async {
8+
fn test_send_trait<T: Send>(_: &T) {}
9+
10+
let stream = futures::stream::pending::<()>();
11+
test_send_trait(&stream);
12+
13+
let fut = stream.collect::<Vec<_>>();
14+
15+
// This line triggers a compilation error
16+
test_send_trait(&fut);
17+
})
18+
}

0 commit comments

Comments
 (0)