Skip to content

Commit

Permalink
Merge #13
Browse files Browse the repository at this point in the history
13: Update pin-project to 0.4.0-alpha.1 r=taiki-e a=taiki-e

Refs: taiki-e/pin-project#21

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed Aug 11, 2019
2 parents b342e91 + 99b2cfb commit ab64531
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ members = ["futures-async-stream-macro"]
[dependencies]
futures-async-stream-macro = { version = "=0.1.0-alpha.2", path = "futures-async-stream-macro", default-features = false }
futures-core-preview = { version = "0.3.0-alpha.17", default-features = false }
pin-project = { version = "0.3.4", default-features = false }
pin-project = { version = "0.4.0-alpha.1", default-features = false }

[dev-dependencies]
compiletest = { version = "0.3.21", package = "compiletest_rs", features = ["stable", "tmp"] }
futures-preview = "0.3.0-alpha.17"
pin-utils = "0.1.0-alpha.4"
romio = "0.3.0-alpha.8"
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ use futures::{
ready,
task::{Context, Poll},
};
use pin_utils::unsafe_pinned;
use pin_project::pin_project;
use std::pin::Pin;

fn foo<S>(stream: S) -> impl Stream<Item = i32>
Expand All @@ -191,22 +191,21 @@ where
Foo { stream }
}

#[pin_project]
struct Foo<S> {
#[pin]
stream: S,
}

impl<S> Foo<S> {
unsafe_pinned!(stream: S);
}

impl<S> Stream for Foo<S>
where
S: Stream<Item = String>,
{
type Item = i32;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
if let Some(x) = ready!(self.stream().poll_next(cx)) {
let this = self.project();
if let Some(x) = ready!(this.stream.poll_next(cx)) {
Poll::Ready(Some(x.parse().unwrap()))
} else {
Poll::Ready(None)
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
//! ready,
//! task::{Context, Poll},
//! };
//! use pin_utils::unsafe_pinned;
//! use pin_project::pin_project;
//! use std::pin::Pin;
//!
//! fn foo<S>(stream: S) -> impl Stream<Item = i32>
Expand All @@ -146,22 +146,21 @@
//! Foo { stream }
//! }
//!
//! #[pin_project]
//! struct Foo<S> {
//! #[pin]
//! stream: S,
//! }
//!
//! impl<S> Foo<S> {
//! unsafe_pinned!(stream: S);
//! }
//!
//! impl<S> Stream for Foo<S>
//! where
//! S: Stream<Item = String>,
//! {
//! type Item = i32;
//!
//! fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
//! if let Some(x) = ready!(self.stream().poll_next(cx)) {
//! let this = self.project();
//! if let Some(x) = ready!(this.stream.poll_next(cx)) {
//! Poll::Ready(Some(x.parse().unwrap()))
//! } else {
//! Poll::Ready(None)
Expand Down
6 changes: 3 additions & 3 deletions src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pin_project::unsafe_project;
use pin_project::pin_project;
use std::{
future::{self, Future},
marker::PhantomData,
Expand All @@ -25,8 +25,8 @@ where
}

/// A wrapper around generators used to implement `Stream` for `async`/`await` code.
#[unsafe_project(Unpin)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[pin_project]
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
struct GenStream<U, T> {
#[pin]
gen: T,
Expand Down

0 comments on commit ab64531

Please sign in to comment.