Skip to content

Commit 1c40a5b

Browse files
authored
Allow yielding !Unpin values. (#50)
1 parent 73500b1 commit 1c40a5b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

async-stream/src/yielder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ thread_local!(static STORE: Cell<*mut ()> = Cell::new(ptr::null_mut()));
3333

3434
// ===== impl Sender =====
3535

36-
impl<T: Unpin> Sender<T> {
36+
impl<T> Sender<T> {
3737
pub fn send(&mut self, value: T) -> impl Future<Output = ()> {
3838
Send { value: Some(value) }
3939
}
@@ -43,7 +43,9 @@ struct Send<T> {
4343
value: Option<T>,
4444
}
4545

46-
impl<T: Unpin> Future for Send<T> {
46+
impl<T> Unpin for Send<T> {}
47+
48+
impl<T> Future for Send<T> {
4749
type Output = ();
4850

4951
fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {

async-stream/tests/stream.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ async fn stream_in_stream() {
158158
assert_eq!(3, values.len());
159159
}
160160

161+
#[tokio::test]
162+
async fn yield_non_unpin_value() {
163+
let s: Vec<_> = stream! {
164+
for i in 0..3 {
165+
yield async move { i };
166+
}
167+
}
168+
.buffered(1)
169+
.collect()
170+
.await;
171+
172+
assert_eq!(s, vec![0, 1, 2]);
173+
}
174+
161175
#[test]
162176
fn test() {
163177
let t = trybuild::TestCases::new();

0 commit comments

Comments
 (0)