Skip to content

Commit a247530

Browse files
authored
Merge pull request #1 from stjepang/into_stream_trait
Remove some Unpin and Send bounds
2 parents 0d3a7f5 + eeff99f commit a247530

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/stream/from_stream.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::pin::Pin;
1010
/// See also: [`IntoStream`].
1111
///
1212
/// [`IntoStream`]: trait.IntoStream.html
13-
pub trait FromStream<T>: Sized + Unpin {
13+
pub trait FromStream<T> {
1414
/// Creates a value from a stream.
1515
///
1616
/// # Examples
@@ -22,7 +22,7 @@ pub trait FromStream<T>: Sized + Unpin {
2222
///
2323
/// // let _five_fives = async_std::stream::repeat(5).take(5);
2424
/// ```
25-
fn from_stream<'a, S: IntoStream<Item = T> + Send + 'a>(
25+
fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
2626
stream: S,
27-
) -> Pin<Box<dyn core::future::Future<Output = Self> + Send + 'a>>;
27+
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>;
2828
}

src/stream/into_stream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ pub trait IntoStream {
1818
type Item;
1919

2020
/// Which kind of stream are we turning this into?
21-
type IntoStream: Stream<Item = Self::Item> + Unpin + Send;
21+
type IntoStream: Stream<Item = Self::Item>;
2222

2323
/// Creates a stream from a value.
2424
fn into_stream(self) -> Self::IntoStream;
2525
}
2626

27-
impl<I: Stream + Unpin + Send> IntoStream for I {
27+
impl<I: Stream> IntoStream for I {
2828
type Item = I::Item;
2929
type IntoStream = I;
3030

src/stream/stream.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cfg_if! {
5454
}
5555
} else {
5656
macro_rules! dyn_ret {
57-
($a:lifetime, $o:ty) => (Pin<Box<dyn core::future::Future<Output = $o> + Send + 'a>>)
57+
($a:lifetime, $o:ty) => (Pin<Box<dyn core::future::Future<Output = $o> + 'a>>)
5858
}
5959
}
6060
}
@@ -162,9 +162,9 @@ pub trait Stream {
162162
///
163163
/// [`stream`]: trait.Stream.html#tymethod.next
164164
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)"]
165-
fn collect<'a, B: FromStream<<Self as Stream>::Item>>(self) -> dyn_ret!('a, B)
165+
fn collect<'a, B>(self) -> dyn_ret!('a, B)
166166
where
167-
Self: futures::stream::Stream + Sized + Send + Unpin + 'a,
167+
Self: futures::stream::Stream + Sized + 'a,
168168
B: FromStream<<Self as futures::stream::Stream>::Item>,
169169
{
170170
FromStream::from_stream(self)

src/vec/from_stream.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ use crate::stream::{FromStream, IntoStream, Stream};
22

33
use std::pin::Pin;
44

5-
impl<T: Unpin + Sized + Send> FromStream<T> for Vec<T> {
5+
impl<T> FromStream<T> for Vec<T> {
66
#[inline]
77
fn from_stream<'a, S: IntoStream<Item = T>>(
88
stream: S,
9-
) -> Pin<Box<dyn core::future::Future<Output = Self> + Send + 'a>>
9+
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
1010
where
11-
<S as IntoStream>::IntoStream: Send + 'a,
11+
<S as IntoStream>::IntoStream: 'a,
1212
{
13-
let mut stream = stream.into_stream();
13+
let stream = stream.into_stream();
14+
1415
Pin::from(Box::new(async move {
16+
pin_utils::pin_mut!(stream);
17+
1518
let mut out = vec![];
1619
while let Some(item) = stream.next().await {
1720
out.push(item);

0 commit comments

Comments
 (0)