From ea4975f3e370bb5142475421be2804c018a6f3a3 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 1 Mar 2019 15:04:05 -0800 Subject: [PATCH 1/2] async-await: fix build for latest nightly --- azure-pipelines.yml | 2 +- src/async_await.rs | 30 ++++++++++++++-- tokio-async-await/src/lib.rs | 70 ------------------------------------ 3 files changed, 28 insertions(+), 74 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c900012c478..677c7292638 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -72,7 +72,7 @@ jobs: parameters: name: async_await displayName: Async / Await - rust: nightly-2019-02-22 + rust: nightly-2019-02-28 noDefaultFeatures: '' benches: true crates: diff --git a/src/async_await.rs b/src/async_await.rs index 900a680362b..579a6b9be65 100644 --- a/src/async_await.rs +++ b/src/async_await.rs @@ -1,8 +1,32 @@ use std::future::Future as StdFuture; +use std::pin::Pin; +use std::task::{Poll, Waker}; -async fn map_ok(future: T) -> Result<(), ()> { - let _ = await!(future); - Ok(()) +fn map_ok(future: T) -> impl StdFuture> { + MapOk(future) +} + +struct MapOk(T); + +impl MapOk { + fn future<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { + unsafe { + Pin::map_unchecked_mut( + self, |x| &mut x.0 + ) + } + } +} + +impl StdFuture for MapOk { + type Output = Result<(), ()>; + + fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll { + match self.future().poll(waker) { + Poll::Ready(_) => Poll::Ready(Ok(())), + Poll::Pending => Poll::Pending, + } + } } /// Like `tokio::run`, but takes an `async` block diff --git a/tokio-async-await/src/lib.rs b/tokio-async-await/src/lib.rs index c434b1b7704..c2eae176bc1 100644 --- a/tokio-async-await/src/lib.rs +++ b/tokio-async-await/src/lib.rs @@ -29,77 +29,7 @@ pub mod io; pub mod sink; pub mod stream; -/* -pub mod prelude { - //! A "prelude" for users of the `tokio` crate. - //! - //! This prelude is similar to the standard library's prelude in that you'll - //! almost always want to import its entire contents, but unlike the standard - //! library's prelude you'll have to do so manually: - //! - //! ``` - //! use tokio::prelude::*; - //! ``` - //! - //! The prelude may grow over time as additional items see ubiquitous use. - - pub use tokio_main::prelude::*; - - #[doc(inline)] - pub use crate::async_await::{ - io::{ - AsyncReadExt, - AsyncWriteExt, - }, - sink::{ - SinkExt, - }, - stream::{ - StreamExt, - }, - }; -} -*/ - // Rename the `await` macro in `std`. This is used by the redefined // `await` macro in this crate. #[doc(hidden)] pub use std::await as std_await; - -/* -use std::future::{Future as StdFuture}; - -fn run>(t: T) { - drop(t); -} - -async fn map_ok(future: T) -> Result<(), ()> { - let _ = await!(future); - Ok(()) -} - -/// Like `tokio::run`, but takes an `async` block -pub fn run_async(future: F) -where F: StdFuture + Send + 'static, -{ - use async_await::compat::backward; - let future = backward::Compat::new(map_ok(future)); - - run(future); - unimplemented!(); -} -*/ - -/* -/// Like `tokio::spawn`, but takes an `async` block -pub fn spawn_async(future: F) -where F: StdFuture + Send + 'static, -{ - use crate::async_await::compat::backward; - - spawn(backward::Compat::new(async || { - let _ = await!(future); - Ok(()) - })); -} -*/ From 2a713465cffade93a72896dffb6860a8b1ecc055 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 1 Mar 2019 15:29:18 -0800 Subject: [PATCH 2/2] fmt --- src/async_await.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/async_await.rs b/src/async_await.rs index 579a6b9be65..4530283cc5f 100644 --- a/src/async_await.rs +++ b/src/async_await.rs @@ -10,11 +10,7 @@ struct MapOk(T); impl MapOk { fn future<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> { - unsafe { - Pin::map_unchecked_mut( - self, |x| &mut x.0 - ) - } + unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) } } }