From 3f5324f0fff9ae82979fc06d1103b6b5e812bef0 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 9 May 2019 12:11:07 +0900 Subject: [PATCH 1/2] Replace await! macro with await syntax --- README.md | 6 +++--- benches/baseline.rs | 12 +++++------ benches/common/mod.rs | 8 +++---- benches/native.rs | 2 +- benches/tokio.rs | 2 +- examples/guessing.rs | 18 ++++++++-------- examples/hello.rs | 4 ++-- examples/tcp-client.rs | 8 +++---- examples/tcp-echo.rs | 6 +++--- examples/tcp-proxy.rs | 9 ++++---- examples/udp-client.rs | 6 +++--- examples/udp-echo.rs | 6 +++--- runtime-attributes/src/lib.rs | 8 +++---- runtime-native/src/lib.rs | 2 +- runtime-raw/src/lib.rs | 4 ++-- runtime-tokio/src/lib.rs | 2 +- src/lib.rs | 8 +++---- src/net/tcp.rs | 40 +++++++++++++++++------------------ src/net/udp.rs | 18 ++++++++-------- src/task.rs | 6 +++--- tests/native.rs | 4 ++-- tests/tokio-current-thread.rs | 4 ++-- tests/tokio.rs | 4 ++-- 23 files changed, 94 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 7567890f..1283caad 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ asynchronous software. ## Examples __UDP Echo Server__ ```rust -#![feature(async_await, await_macro)] +#![feature(async_await)] use runtime::net::UdpSocket; @@ -81,8 +81,8 @@ async fn main() -> std::io::Result<()> { println!("Listening on {}", socket.local_addr()?); loop { - let (recv, peer) = await!(socket.recv_from(&mut buf))?; - let sent = await!(socket.send_to(&buf[..recv], &peer))?; + let (recv, peer) = socket.recv_from(&mut buf).await?; + let sent = socket.send_to(&buf[..recv], &peer).await?; println!("Sent {} out of {} bytes to {}", sent, recv, peer); } } diff --git a/benches/baseline.rs b/benches/baseline.rs index 18a6e95c..0f15d20e 100644 --- a/benches/baseline.rs +++ b/benches/baseline.rs @@ -1,4 +1,4 @@ -#![feature(test, async_await, await_macro)] +#![feature(test, async_await)] extern crate test; @@ -43,13 +43,13 @@ mod baseline { let tasks = (0..300) .map(|_| { spawn(async move { - await!(Task { depth: 0 }); + Task { depth: 0 }.await; }) }) .collect::>(); for task in tasks { - await!(task); + task.await; } }) }); @@ -62,7 +62,7 @@ mod baseline { let tasks = (0..25_000).map(|_| spawn(async {})).collect::>(); for task in tasks { - await!(task); + task.await; } }) }); @@ -106,7 +106,7 @@ mod baseline { .collect::>(); for task in tasks { - await!(task); + task.await; } }) }); @@ -121,7 +121,7 @@ mod baseline { let (tx, rx) = futures::channel::oneshot::channel(); let fut = async move { - let t = await!(fut); + let t = fut.await; let _ = tx.send(t); }; diff --git a/benches/common/mod.rs b/benches/common/mod.rs index 58f6b83a..a8c136fd 100644 --- a/benches/common/mod.rs +++ b/benches/common/mod.rs @@ -31,13 +31,13 @@ macro_rules! benchmark_suite { let tasks = (0..300) .map(|_| { runtime::spawn(async { - await!(Task { depth: 0 }); + Task { depth: 0 }.await; }) }) .collect::>(); for task in tasks { - await!(task); + task.await; } } @@ -48,7 +48,7 @@ macro_rules! benchmark_suite { .collect::>(); for task in tasks { - await!(task); + task.await; } } @@ -89,7 +89,7 @@ macro_rules! benchmark_suite { .collect::>(); for task in tasks { - await!(task); + task.await; } } }; diff --git a/benches/native.rs b/benches/native.rs index 4967bf81..86faf147 100644 --- a/benches/native.rs +++ b/benches/native.rs @@ -1,4 +1,4 @@ -#![feature(test, async_await, await_macro)] +#![feature(test, async_await)] #![warn(rust_2018_idioms)] extern crate test; diff --git a/benches/tokio.rs b/benches/tokio.rs index 7d799345..011f8e70 100644 --- a/benches/tokio.rs +++ b/benches/tokio.rs @@ -1,4 +1,4 @@ -#![feature(test, async_await, await_macro)] +#![feature(test, async_await)] #![warn(rust_2018_idioms)] extern crate test; diff --git a/examples/guessing.rs b/examples/guessing.rs index 7d1dbfd2..a074fa9d 100644 --- a/examples/guessing.rs +++ b/examples/guessing.rs @@ -7,7 +7,7 @@ //! $ nc localhost 8080 //! ``` -#![feature(async_await, await_macro)] +#![feature(async_await)] use futures::prelude::*; use rand::Rng; @@ -21,14 +21,14 @@ async fn play(stream: TcpStream) -> Result<(), failure::Error> { let (reader, writer) = &mut stream.split(); let mut buf = vec![0u8; 1024]; - await!(writer.write_all(b"Guess the number!\n"))?; + writer.write_all(b"Guess the number!\n").await?; let secret_number = rand::thread_rng().gen_range(1, 101); loop { - await!(writer.write_all(b"Please input your guess.\n"))?; + writer.write_all(b"Please input your guess.\n").await?; - let len = await!(reader.read(&mut buf))?; + let len = reader.read(&mut buf).await?; if len == 0 { return Ok(()); } @@ -41,13 +41,13 @@ async fn play(stream: TcpStream) -> Result<(), failure::Error> { }; let msg = format!("You guessed: {}\n", guess); - await!(writer.write_all(msg.as_bytes()))?; + writer.write_all(msg.as_bytes()).await?; match guess.cmp(&secret_number) { - Ordering::Less => await!(writer.write_all(b"Too small!\n"))?, - Ordering::Greater => await!(writer.write_all(b"Too big!\n"))?, + Ordering::Less => writer.write_all(b"Too small!\n").await?, + Ordering::Greater => writer.write_all(b"Too big!\n").await?, Ordering::Equal => { - await!(writer.write_all(b"You win!\n"))?; + writer.write_all(b"You win!\n").await?; break; } } @@ -62,7 +62,7 @@ async fn main() -> Result<(), failure::Error> { println!("Listening on {}", &listener.local_addr()?); let mut incoming = listener.incoming(); - while let Some(stream) = await!(incoming.next()) { + while let Some(stream) = incoming.next().await { runtime::spawn(play(stream?)); } Ok(()) diff --git a/examples/hello.rs b/examples/hello.rs index d0cfb382..0598a9ce 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,4 +1,4 @@ -#![feature(async_await, await_macro)] +#![feature(async_await)] async fn say_hi() { println!("Hello world! 🤖"); @@ -6,5 +6,5 @@ async fn say_hi() { #[runtime::main] async fn main() { - await!(say_hi()); + say_hi().await; } diff --git a/examples/tcp-client.rs b/examples/tcp-client.rs index 31c92ffe..dc6fe8d2 100644 --- a/examples/tcp-client.rs +++ b/examples/tcp-client.rs @@ -6,22 +6,22 @@ //! $ cargo run --example tcp-echo //! ``` -#![feature(async_await, await_macro)] +#![feature(async_await)] use futures::prelude::*; use runtime::net::TcpStream; #[runtime::main] async fn main() -> Result<(), failure::Error> { - let mut stream = await!(TcpStream::connect("127.0.0.1:8080"))?; + let mut stream = TcpStream::connect("127.0.0.1:8080").await?; println!("Connected to {}", &stream.peer_addr()?); let msg = "hello world"; println!("<- {}", msg); - await!(stream.write_all(msg.as_bytes()))?; + stream.write_all(msg.as_bytes()).await?; let mut buf = vec![0u8; 1024]; - await!(stream.read(&mut buf))?; + stream.read(&mut buf).await?; println!("-> {}\n", String::from_utf8(buf)?); Ok(()) diff --git a/examples/tcp-echo.rs b/examples/tcp-echo.rs index 300ae5a4..26a34959 100644 --- a/examples/tcp-echo.rs +++ b/examples/tcp-echo.rs @@ -3,7 +3,7 @@ //! Run the server and connect to it with `nc 127.0.0.1 8080`. //! The server will wait for you to enter lines of text and then echo them back. -#![feature(async_await, await_macro)] +#![feature(async_await)] use futures::prelude::*; use runtime::net::TcpListener; @@ -15,13 +15,13 @@ async fn main() -> std::io::Result<()> { // accept connections and process them in parallel let mut incoming = listener.incoming(); - while let Some(stream) = await!(incoming.next()) { + while let Some(stream) = incoming.next().await { runtime::spawn(async move { let stream = stream?; println!("Accepting from: {}", stream.peer_addr()?); let (reader, writer) = &mut stream.split(); - await!(reader.copy_into(writer))?; + reader.copy_into(writer).await?; Ok::<(), std::io::Error>(()) }); } diff --git a/examples/tcp-proxy.rs b/examples/tcp-proxy.rs index 1e132106..1d9f511f 100644 --- a/examples/tcp-proxy.rs +++ b/examples/tcp-proxy.rs @@ -1,6 +1,7 @@ //! A TCP proxy server. Forwards connections from port 8081 to port 8080. -#![feature(async_await, await_macro)] +#![feature(async_await)] +#![feature(await_macro)] // TODO: When the next version of futures-preview released, remove this. use futures::prelude::*; use futures::try_join; @@ -13,10 +14,10 @@ async fn main() -> std::io::Result<()> { // accept connections and process them serially let mut incoming = listener.incoming(); - while let Some(client) = await!(incoming.next()) { + while let Some(client) = incoming.next().await { let handle = runtime::spawn(async move { let client = client?; - let server = await!(TcpStream::connect("127.0.0.1:8080"))?; + let server = TcpStream::connect("127.0.0.1:8080").await?; println!( "Proxying {} to {}", client.peer_addr()?, @@ -32,7 +33,7 @@ async fn main() -> std::io::Result<()> { Ok::<(), std::io::Error>(()) }); - await!(handle)?; + handle.await?; } Ok(()) } diff --git a/examples/udp-client.rs b/examples/udp-client.rs index 7ad552e7..56b52077 100644 --- a/examples/udp-client.rs +++ b/examples/udp-client.rs @@ -1,4 +1,4 @@ -#![feature(async_await, await_macro)] +#![feature(async_await)] //! UDP client. //! @@ -16,10 +16,10 @@ async fn main() -> std::io::Result<()> { let msg = "hello world"; println!("<- {}", msg); - await!(socket.send_to(msg.as_bytes(), "127.0.0.1:8080"))?; + socket.send_to(msg.as_bytes(), "127.0.0.1:8080").await?; let mut buf = vec![0u8; 1024]; - await!(socket.recv_from(&mut buf))?; + socket.recv_from(&mut buf).await?; println!("-> {}\n", String::from_utf8_lossy(&mut buf)); Ok(()) diff --git a/examples/udp-echo.rs b/examples/udp-echo.rs index 4680bceb..f4eccf02 100644 --- a/examples/udp-echo.rs +++ b/examples/udp-echo.rs @@ -1,4 +1,4 @@ -#![feature(async_await, await_macro)] +#![feature(async_await)] //! UDP echo server. //! @@ -17,8 +17,8 @@ async fn main() -> std::io::Result<()> { println!("Listening on {}", socket.local_addr()?); loop { - let (recv, peer) = await!(socket.recv_from(&mut buf))?; - let sent = await!(socket.send_to(&buf[..recv], &peer))?; + let (recv, peer) = socket.recv_from(&mut buf).await?; + let sent = socket.send_to(&buf[..recv], &peer).await?; println!("Sent {} out of {} bytes to {}", sent, recv, peer); } } diff --git a/runtime-attributes/src/lib.rs b/runtime-attributes/src/lib.rs index bd3e9ba0..2e01ac1a 100644 --- a/runtime-attributes/src/lib.rs +++ b/runtime-attributes/src/lib.rs @@ -3,7 +3,7 @@ #![forbid(unsafe_code, future_incompatible, rust_2018_idioms)] #![deny(missing_debug_implementations, nonstandard_style)] -#![feature(async_await, await_macro)] +#![feature(async_await)] #![recursion_limit = "512"] extern crate proc_macro; @@ -62,7 +62,7 @@ pub fn main(attr: TokenStream, item: TokenStream) -> TokenStream { } runtime::raw::enter(#rt, async { - await!(main()) + main().await }) } @@ -120,13 +120,13 @@ pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream { /// # Examples /// /// ```ignore -/// #![feature(async_await, await_macro, test)] +/// #![feature(async_await, test)] /// /// extern crate test; /// /// #[runtime::test] /// async fn spawn_and_await() { -/// await!(runtime::spawn(async {})); +/// runtime::spawn(async {}).await; /// } /// ``` #[proc_macro_attribute] diff --git a/runtime-native/src/lib.rs b/runtime-native/src/lib.rs index f4250298..25ff547c 100644 --- a/runtime-native/src/lib.rs +++ b/runtime-native/src/lib.rs @@ -1,7 +1,7 @@ //! A cross-platform asynchronous [Runtime](https://github.com/rustasync/runtime). See the [Runtime //! documentation](https://docs.rs/runtime) for more details. -#![feature(async_await, await_macro)] +#![feature(async_await)] #![deny(unsafe_code)] #![warn( missing_debug_implementations, diff --git a/runtime-raw/src/lib.rs b/runtime-raw/src/lib.rs index 0be99f67..f5eddb85 100644 --- a/runtime-raw/src/lib.rs +++ b/runtime-raw/src/lib.rs @@ -5,7 +5,7 @@ //! perform IO, then there's no need to bother with any of these types as they will have been //! implemented for you already. -#![feature(async_await, await_macro)] +#![feature(async_await)] #![deny(unsafe_code)] #![warn( missing_debug_implementations, @@ -61,7 +61,7 @@ where let (tx, rx) = futures::channel::oneshot::channel(); let fut = async move { - let t = await!(fut); + let t = fut.await; let _ = tx.send(t); }; diff --git a/runtime-tokio/src/lib.rs b/runtime-tokio/src/lib.rs index 122b737e..03563793 100644 --- a/runtime-tokio/src/lib.rs +++ b/runtime-tokio/src/lib.rs @@ -2,7 +2,7 @@ //! [Runtime](https://github.com/rustasync/runtime). See the [Runtime //! documentation](https://docs.rs/runtime) for more details. -#![feature(async_await, await_macro)] +#![feature(async_await)] #![warn( missing_debug_implementations, missing_docs, diff --git a/src/lib.rs b/src/lib.rs index 28db38c6..93559ce0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! ## Examples //! __UDP Echo Server__ //! ```no_run -//! #![feature(async_await, await_macro)] +//! #![feature(async_await)] //! //! use runtime::net::UdpSocket; //! @@ -28,8 +28,8 @@ //! println!("Listening on {}", socket.local_addr()?); //! //! loop { -//! let (recv, peer) = await!(socket.recv_from(&mut buf))?; -//! let sent = await!(socket.send_to(&buf[..recv], &peer))?; +//! let (recv, peer) = socket.recv_from(&mut buf).await?; +//! let sent = socket.send_to(&buf[..recv], &peer).await?; //! println!("Sent {} out of {} bytes to {}", sent, recv, peer); //! } //! } @@ -85,7 +85,7 @@ //! - [Runtime Tokio](https://docs.rs/runtime-tokio) provides a thread pool, bindings to the OS, and //! a work-stealing scheduler. -#![feature(async_await, await_macro)] +#![feature(async_await)] #![deny(unsafe_code)] #![warn( missing_debug_implementations, diff --git a/src/net/tcp.rs b/src/net/tcp.rs index a315decf..211e5685 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -46,22 +46,22 @@ use futures::task::{Context, Poll}; /// /// ## Examples /// ```no_run -/// #![feature(async_await, await_macro)] +/// #![feature(async_await)] /// /// use futures::prelude::*; /// use runtime::net::TcpStream; /// /// #[runtime::main] /// async fn main() -> Result<(), failure::Error> { -/// let mut stream = await!(TcpStream::connect("127.0.0.1:8080"))?; +/// let mut stream = TcpStream::connect("127.0.0.1:8080").await?; /// println!("Connected to {}", &stream.peer_addr()?); /// /// let msg = "hello world"; /// println!("<- {}", msg); -/// await!(stream.write_all(msg.as_bytes()))?; +/// stream.write_all(msg.as_bytes()).await?; /// /// let mut buf = vec![0u8; 1024]; -/// await!(stream.read(&mut buf))?; +/// stream.read(&mut buf).await?; /// println!("-> {}\n", std::str::from_utf8(&mut buf)?); /// /// Ok(()) @@ -85,11 +85,11 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// use runtime::net::TcpStream; /// /// # async fn connect_localhost() -> std::io::Result<()> { - /// let stream = await!(TcpStream::connect("127.0.0.1:0"))?; + /// let stream = TcpStream::connect("127.0.0.1:0").await?; /// # Ok(())} /// ``` pub fn connect(addr: A) -> Connect { @@ -105,13 +105,13 @@ impl TcpStream { /// /// ## Examples /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// use runtime::net::TcpStream; /// use std::net::{IpAddr, Ipv4Addr}; /// /// # #[runtime::main] /// # async fn main() -> std::io::Result<()> { - /// let stream = await!(TcpStream::connect("127.0.0.1:8080"))?; + /// let stream = TcpStream::connect("127.0.0.1:8080").await?; /// /// let expected = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); /// assert_eq!(stream.local_addr()?.ip(), expected); @@ -125,12 +125,12 @@ impl TcpStream { /// /// ## Examples /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// use runtime::net::TcpStream; /// use std::net::{IpAddr, Ipv4Addr}; /// /// # async fn connect_localhost() -> std::io::Result<()> { - /// let stream = await!(TcpStream::connect("127.0.0.1:8080"))?; + /// let stream = TcpStream::connect("127.0.0.1:8080").await?; /// /// let expected = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); /// assert_eq!(stream.peer_addr()?.ip(), expected); @@ -151,14 +151,14 @@ impl TcpStream { /// # Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// /// use std::net::Shutdown; /// use runtime::net::TcpStream; /// /// # #[runtime::main] /// # async fn main() -> std::io::Result<()> { - /// let stream = await!(TcpStream::connect("127.0.0.1:8080"))?; + /// let stream = TcpStream::connect("127.0.0.1:8080").await?; /// stream.shutdown(Shutdown::Both)?; /// # Ok(()) } /// ``` @@ -290,7 +290,7 @@ impl fmt::Debug for Connect { /// /// # Examples /// ```ignore -/// #![feature(async_await, await_macro)] +/// #![feature(async_await)] /// /// use futures::prelude::*; /// use runtime::net::TcpListener; @@ -302,13 +302,13 @@ impl fmt::Debug for Connect { /// /// // accept connections and process them in parallel /// let mut incoming = listener.incoming(); -/// while let Some(stream) = await!(incoming.next()) { +/// while let Some(stream) = incoming.next().await { /// runtime::spawn(async move { /// let stream = stream?; /// println!("Accepting from: {}", stream.peer_addr()?); /// /// let (reader, writer) = &mut stream.split(); -/// await!(reader.copy_into(writer))?; +/// reader.copy_into(writer).await?; /// Ok::<(), std::io::Error>(()) /// }); /// } @@ -366,7 +366,7 @@ impl TcpListener { /// # Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// /// use runtime::net::TcpListener; /// use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; @@ -396,7 +396,7 @@ impl TcpListener { /// ## Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// /// use futures::prelude::*; /// use runtime::net::TcpListener; @@ -404,7 +404,7 @@ impl TcpListener { /// # async fn work () -> Result<(), Box> { /// let mut listener = TcpListener::bind("127.0.0.1:0")?; /// let mut incoming = listener.incoming(); - /// while let Some(stream) = await!(incoming.next()) { + /// while let Some(stream) = incoming.next().await { /// match stream { /// Ok(stream) => println!("new client!"), /// Err(e) => { /* connection failed */ } @@ -429,14 +429,14 @@ impl TcpListener { /// ## Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// /// use futures::prelude::*; /// use runtime::net::TcpListener; /// /// # async fn work () -> Result<(), Box> { /// let mut listener = TcpListener::bind("127.0.0.1:0")?; - /// let (stream, addr) = await!(listener.accept())?; + /// let (stream, addr) = listener.accept().await?; /// println!("Connected to {}", addr); /// # Ok(())} /// ``` diff --git a/src/net/udp.rs b/src/net/udp.rs index 3897a7d3..5f87d16e 100644 --- a/src/net/udp.rs +++ b/src/net/udp.rs @@ -36,7 +36,7 @@ use std::task::{Context, Poll}; /// /// ## Examples /// ```no_run -/// #![feature(async_await, await_macro)] +/// #![feature(async_await)] /// /// use runtime::net::UdpSocket; /// @@ -48,8 +48,8 @@ use std::task::{Context, Poll}; /// println!("Listening on {}", socket.local_addr()?); /// /// loop { -/// let (recv, peer) = await!(socket.recv_from(&mut buf))?; -/// let sent = await!(socket.send_to(&buf[..recv], &peer))?; +/// let (recv, peer) = socket.recv_from(&mut buf).await?; +/// let sent = socket.send_to(&buf[..recv], &peer).await?; /// println!("Sent {} out of {} bytes to {}", sent, recv, peer); /// } /// } @@ -120,7 +120,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// # use std::error::Error; /// use runtime::net::UdpSocket; /// @@ -135,7 +135,7 @@ impl UdpSocket { /// let mut socket = UdpSocket::bind("127.0.0.1:0")?; /// /// let addr = "127.0.0.1:7878"; - /// let sent = await!(socket.send_to(THE_MERCHANT_OF_VENICE, &addr))?; + /// let sent = socket.send_to(THE_MERCHANT_OF_VENICE, &addr).await?; /// println!("Sent {} bytes to {}", sent, addr); /// # Ok(()) /// # } @@ -163,7 +163,7 @@ impl UdpSocket { /// # Examples /// /// ```no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// # use std::error::Error; /// use runtime::net::UdpSocket; /// @@ -171,7 +171,7 @@ impl UdpSocket { /// let mut socket = UdpSocket::bind("127.0.0.1:0")?; /// /// let mut buf = vec![0; 1024]; - /// let (recv, peer) = await!(socket.recv_from(&mut buf))?; + /// let (recv, peer) = socket.recv_from(&mut buf).await?; /// println!("Received {} bytes from {}", recv, peer); /// # Ok(buf) /// # } @@ -289,7 +289,7 @@ impl UdpSocket { /// # Examples /// /// ```rust,no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// /// use runtime::net::UdpSocket; /// use std::net::Ipv4Addr; @@ -316,7 +316,7 @@ impl UdpSocket { /// # Examples /// /// ```rust,no_run - /// #![feature(async_await, await_macro)] + /// #![feature(async_await)] /// /// use runtime::net::UdpSocket; /// use std::net::{Ipv6Addr, SocketAddr}; diff --git a/src/task.rs b/src/task.rs index ea4d32e3..5568cb68 100644 --- a/src/task.rs +++ b/src/task.rs @@ -12,7 +12,7 @@ use futures::task::{Context, Poll}; /// # Examples /// /// ``` -/// #![feature(async_await, await_macro)] +/// #![feature(async_await)] /// /// #[runtime::main] /// async fn main() { @@ -20,7 +20,7 @@ use futures::task::{Context, Poll}; /// println!("running the future"); /// 42 /// }); -/// assert_eq!(await!(handle), 42); +/// assert_eq!(handle.await, 42); /// } /// ``` pub fn spawn(fut: F) -> JoinHandle @@ -31,7 +31,7 @@ where let (tx, rx) = futures::channel::oneshot::channel(); let fut = async move { - let t = await!(fut); + let t = fut.await; let _ = tx.send(t); }; diff --git a/tests/native.rs b/tests/native.rs index b39d352d..7b5a0f20 100644 --- a/tests/native.rs +++ b/tests/native.rs @@ -1,4 +1,4 @@ -#![feature(async_await, await_macro)] +#![feature(async_await)] use runtime_native::Native; @@ -8,5 +8,5 @@ async fn spawn() { println!("hello planet from Native"); 42 }); - assert_eq!(await!(handle), 42); + assert_eq!(handle.await, 42); } diff --git a/tests/tokio-current-thread.rs b/tests/tokio-current-thread.rs index 10330c98..ab70c36f 100644 --- a/tests/tokio-current-thread.rs +++ b/tests/tokio-current-thread.rs @@ -1,4 +1,4 @@ -#![feature(async_await, await_macro)] +#![feature(async_await)] #[runtime::test(runtime_tokio::TokioCurrentThread)] async fn spawn() { @@ -6,5 +6,5 @@ async fn spawn() { println!("hello planet from Tokio current-thread"); 42 }); - assert_eq!(await!(handle), 42); + assert_eq!(handle.await, 42); } diff --git a/tests/tokio.rs b/tests/tokio.rs index 4bc4d3d5..6fb605c2 100644 --- a/tests/tokio.rs +++ b/tests/tokio.rs @@ -1,4 +1,4 @@ -#![feature(async_await, await_macro)] +#![feature(async_await)] use runtime_tokio::Tokio; @@ -8,5 +8,5 @@ async fn spawn() { println!("hello planet from Tokio"); 42 }); - assert_eq!(await!(handle), 42); + assert_eq!(handle.await, 42); } From 93c91810c6c615afb67b5b337f8b34f7a0d93449 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 11 May 2019 14:30:57 +0900 Subject: [PATCH 2/2] Update futures-preview to 0.3.0-alpha.16 --- Cargo.toml | 8 ++++++-- examples/tcp-proxy.rs | 1 - runtime-native/Cargo.toml | 2 +- runtime-raw/Cargo.toml | 2 +- runtime-tokio/Cargo.toml | 2 +- src/net/tcp.rs | 12 ++++++------ 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3008b43..e4bfd098 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency" edition = "2018" [dependencies] -futures-preview = "0.3.0-alpha.15" +futures-preview = "0.3.0-alpha.16" runtime-attributes = { path = "runtime-attributes", version = "0.3.0-alpha.3" } runtime-raw = { path = "runtime-raw", version = "0.3.0-alpha.2" } runtime-native = { path = "runtime-native", version = "0.3.0-alpha.2" } @@ -21,7 +21,7 @@ runtime-native = { path = "runtime-native", version = "0.3.0-alpha.2" } [dev-dependencies] failure = "0.1.5" futures01 = { package = "futures", version = "0.1" } -futures-preview = { version = "0.3.0-alpha.15", features = ["nightly", "async-await"] } +futures-preview = { version = "0.3.0-alpha.16", features = ["nightly", "async-await"] } juliex = "0.3.0-alpha.5" mio = "0.6.16" rand = "0.6.5" @@ -40,3 +40,7 @@ members = [ "runtime-raw", "runtime-tokio", ] + +[patch.crates-io] +romio = { git = "https://github.com/dbcfd/romio", branch = "futures-changes" } +juliex = { git = "https://github.com/taiki-e/juliex", branch = "await" } diff --git a/examples/tcp-proxy.rs b/examples/tcp-proxy.rs index 1d9f511f..2f711536 100644 --- a/examples/tcp-proxy.rs +++ b/examples/tcp-proxy.rs @@ -1,7 +1,6 @@ //! A TCP proxy server. Forwards connections from port 8081 to port 8080. #![feature(async_await)] -#![feature(await_macro)] // TODO: When the next version of futures-preview released, remove this. use futures::prelude::*; use futures::try_join; diff --git a/runtime-native/Cargo.toml b/runtime-native/Cargo.toml index 36532c30..cb3a8bb2 100644 --- a/runtime-native/Cargo.toml +++ b/runtime-native/Cargo.toml @@ -13,7 +13,7 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency" edition = "2018" [dependencies] -futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] } +futures-preview = { version = "0.3.0-alpha.16", features = ["compat"] } runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.2" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/runtime-raw/Cargo.toml b/runtime-raw/Cargo.toml index bb918e8d..38056a8d 100644 --- a/runtime-raw/Cargo.toml +++ b/runtime-raw/Cargo.toml @@ -13,4 +13,4 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency" edition = "2018" [dependencies] -futures-preview = "0.3.0-alpha.15" +futures-preview = "0.3.0-alpha.16" diff --git a/runtime-tokio/Cargo.toml b/runtime-tokio/Cargo.toml index 52662145..a672aee8 100644 --- a/runtime-tokio/Cargo.toml +++ b/runtime-tokio/Cargo.toml @@ -13,7 +13,7 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency" edition = "2018" [dependencies] -futures-preview = { version = "0.3.0-alpha.15", features = ["compat", "io-compat"] } +futures-preview = { version = "0.3.0-alpha.16", features = ["compat", "io-compat"] } futures01 = { package = "futures", version = "0.1" } lazy_static = "1.3.0" mio = "0.6.16" diff --git a/src/net/tcp.rs b/src/net/tcp.rs index 211e5685..f1bc14b9 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -176,12 +176,12 @@ impl AsyncRead for TcpStream { self.inner.as_mut().poll_read(cx, buf) } - fn poll_vectored_read( + fn poll_read_vectored( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - vec: &mut [&mut IoVec], + bufs: &mut [IoSliceMut<'_>], ) -> Poll> { - self.inner.as_mut().poll_vectored_read(cx, vec) + self.inner.as_mut().poll_read_vectored(cx, bufs) } } @@ -202,12 +202,12 @@ impl AsyncWrite for TcpStream { self.inner.as_mut().poll_close(cx) } - fn poll_vectored_write( + fn poll_write_vectored( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - vec: &[&IoVec], + bufs: &[IoSlice<'_>], ) -> Poll> { - self.inner.as_mut().poll_vectored_write(cx, vec) + self.inner.as_mut().poll_write_vectored(cx, bufs) } }