diff options
author | Gurwinder Singh <vargwin@gmail.com> | 2019-07-15 23:13:54 +0530 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2019-07-15 10:43:54 -0700 |
commit | 83273b8b50fd4e7a68c83f9086e2f1bd513174d7 (patch) | |
tree | 904db56e391293e4ddf40e326a514ddb98d7b7c4 | |
parent | ca708d6d8783b4fc86ccc059fb7a40e14edfe812 (diff) |
chore: use ready macro from `futures-core` (#1300)
48 files changed, 42 insertions, 137 deletions
diff --git a/tokio-io/Cargo.toml b/tokio-io/Cargo.toml index 8f420495..2561ac21 100644 --- a/tokio-io/Cargo.toml +++ b/tokio-io/Cargo.toml @@ -24,6 +24,7 @@ publish = false [dependencies] bytes = "0.4.7" log = "0.4" +futures-core-preview = "0.3.0-alpha.17" [dev-dependencies] pin-utils = "0.1.0-alpha.4" diff --git a/tokio-io/src/async_read.rs b/tokio-io/src/async_read.rs index 4eeaa7bb..1b7eaa6c 100644 --- a/tokio-io/src/async_read.rs +++ b/tokio-io/src/async_read.rs @@ -1,6 +1,7 @@ //use crate::split::{ReadHalf, WriteHalf}; //use crate::{framed, split, AsyncWrite}; use bytes::BufMut; +use futures_core::ready; use std::io; use std::ops::DerefMut; use std::pin::Pin; diff --git a/tokio-io/src/async_write.rs b/tokio-io/src/async_write.rs index 80ec74d1..7bcb4339 100644 --- a/tokio-io/src/async_write.rs +++ b/tokio-io/src/async_write.rs @@ -1,5 +1,6 @@ //use crate::AsyncRead; use bytes::Buf; +use futures_core::ready; use std::io; use std::ops::DerefMut; use std::pin::Pin; diff --git a/tokio-io/src/lib.rs b/tokio-io/src/lib.rs index 81a11f8f..165cc1ca 100644 --- a/tokio-io/src/lib.rs +++ b/tokio-io/src/lib.rs @@ -12,15 +12,6 @@ //! [found online]: https://tokio.rs/docs/ //! [low level details]: https://tokio.rs/docs/going-deeper-tokio/core-low-level/ -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - mod async_read; mod async_write; diff --git a/tokio-reactor/Cargo.toml b/tokio-reactor/Cargo.toml index ed939a9c..f504ccae 100644 --- a/tokio-reactor/Cargo.toml +++ b/tokio-reactor/Cargo.toml @@ -33,6 +33,7 @@ slab = "0.4.0" tokio-executor = { version = "0.2.0", path = "../tokio-executor" } tokio-io = { version = "0.2.0", path = "../tokio-io" } tokio-sync = { version = "0.2.0", path = "../tokio-sync" } +futures-core-preview = "0.3.0-alpha.17" [dev-dependencies] num_cpus = "1.8.0" diff --git a/tokio-reactor/src/lib.rs b/tokio-reactor/src/lib.rs index ff2ab686..5eae81da 100644 --- a/tokio-reactor/src/lib.rs +++ b/tokio-reactor/src/lib.rs @@ -32,15 +32,6 @@ //! [`PollEvented`]: struct.PollEvented.html //! [reactor module]: https://docs.rs/tokio/0.1/tokio/reactor/index.html -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(v) => v, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - mod poll_evented; mod registration; mod sharded_rwlock; diff --git a/tokio-reactor/src/poll_evented.rs b/tokio-reactor/src/poll_evented.rs index 5b280294..50f21434 100644 --- a/tokio-reactor/src/poll_evented.rs +++ b/tokio-reactor/src/poll_evented.rs @@ -1,4 +1,5 @@ use crate::{Handle, Registration}; +use futures_core::ready; use mio; use mio::event::Evented; use std::fmt; diff --git a/tokio-sync/Cargo.toml b/tokio-sync/Cargo.toml index 66022b30..e8fddf16 100644 --- a/tokio-sync/Cargo.toml +++ b/tokio-sync/Cargo.toml @@ -22,13 +22,13 @@ categories = ["asynchronous"] publish = false [features] -async-traits = ["tokio-futures", "futures-core-preview"] +async-traits = ["tokio-futures"] [dependencies] async-util = { git = "https://github.com/tokio-rs/async" } tokio-futures = { path = "../tokio-futures", optional = true } fnv = "1.0.6" -futures-core-preview = { version = "0.3.0-alpha.17", optional = true } +futures-core-preview = { version = "0.3.0-alpha.17" } [dev-dependencies] env_logger = { version = "0.5", default-features = false } diff --git a/tokio-sync/src/lib.rs b/tokio-sync/src/lib.rs index 384740ac..00f9b700 100644 --- a/tokio-sync/src/lib.rs +++ b/tokio-sync/src/lib.rs @@ -21,19 +21,6 @@ macro_rules! debug { } } -/// Unwrap a ready value or propagate `Poll::Pending`. -#[macro_export] -macro_rules! ready { - ($e:expr) => {{ - use std::task::Poll::{Pending, Ready}; - - match $e { - Ready(v) => v, - Pending => return Pending, - } - }}; -} - macro_rules! if_fuzz { ($($t:tt)*) => {{ if false { $($t)* } diff --git a/tokio-sync/src/lock.rs b/tokio-sync/src/lock.rs index 10f6a112..8b2bc0bc 100644 --- a/tokio-sync/src/lock.rs +++ b/tokio-sync/src/lock.rs @@ -42,6 +42,7 @@ use crate::semaphore; +use futures_core::ready; use std::cell::UnsafeCell; use std::fmt; use std::future::Future; diff --git a/tokio-sync/src/oneshot.rs b/tokio-sync/src/oneshot.rs index 910d24dd..86f1cd82 100644 --- a/tokio-sync/src/oneshot.rs +++ b/tokio-sync/src/oneshot.rs @@ -2,6 +2,7 @@ use crate::loom::{sync::atomic::AtomicUsize, sync::CausalCell}; +use futures_core::ready; use std::fmt; use std::future::Future; use std::mem::{self, ManuallyDrop}; diff --git a/tokio-sync/src/watch.rs b/tokio-sync/src/watch.rs index ed35b0aa..91d5d2b5 100644 --- a/tokio-sync/src/watch.rs +++ b/tokio-sync/src/watch.rs @@ -58,6 +58,7 @@ use crate::task::AtomicWaker; use core::task::Poll::{Pending, Ready}; use core::task::{Context, Poll}; use fnv::FnvHashMap; +use futures_core::ready; use std::ops; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::SeqCst; diff --git a/tokio-sync/tests/fuzz_oneshot.rs b/tokio-sync/tests/fuzz_oneshot.rs index f8987af6..eb4dfcde 100644 --- a/tokio-sync/tests/fuzz_oneshot.rs +++ b/tokio-sync/tests/fuzz_oneshot.rs @@ -1,19 +1,6 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -/// Unwrap a ready value or propagate `Async::Pending`. -#[macro_export] -macro_rules! ready { - ($e:expr) => {{ - use std::task::Poll::{Pending, Ready}; - - match $e { - Ready(v) => v, - Pending => return Pending, - } - }}; -} - #[path = "../src/oneshot.rs"] #[allow(warnings)] mod oneshot; diff --git a/tokio-sync/tests/fuzz_semaphore.rs b/tokio-sync/tests/fuzz_semaphore.rs index ca2fda8b..55d6bf0d 100644 --- a/tokio-sync/tests/fuzz_semaphore.rs +++ b/tokio-sync/tests/fuzz_semaphore.rs @@ -10,6 +10,7 @@ mod semaphore; use crate::semaphore::*; use async_util::future::poll_fn; +use futures_core::ready; use loom::futures::block_on; use loom::thread; use std::future::Future; @@ -20,19 +21,6 @@ use std::sync::Arc; use std::task::Poll::Ready; use std::task::{Context, Poll}; -/// Unwrap a ready value or propagate `Poll::Pending`. -#[macro_export] -macro_rules! ready { - ($e:expr) => {{ - use std::task::Poll::{Pending, Ready}; - - match $e { - Ready(v) => v, - Pending => return Pending, - } - }}; -} - #[test] fn basic_usage() { const NUM: usize = 2; diff --git a/tokio-tcp/Cargo.toml b/tokio-tcp/Cargo.toml index 2bb387d9..776f14b9 100644 --- a/tokio-tcp/Cargo.toml +++ b/tokio-tcp/Cargo.toml @@ -22,7 +22,7 @@ categories = ["asynchronous"] publish = false [features] -incoming = ["futures-core-preview"] +incoming = [] [dependencies] async-util = { git = "https://github.com/tokio-rs/async" } @@ -33,7 +33,7 @@ mio = "0.6.14" iovec = "0.1" # optionals -futures-core-preview = { version = "0.3.0-alpha.17", optional = true } +futures-core-preview = { version = "0.3.0-alpha.17" } [dev-dependencies] #env_logger = { version = "0.5", default-features = false } diff --git a/tokio-tcp/src/incoming.rs b/tokio-tcp/src/incoming.rs index 566734de..00c2e01d 100644 --- a/tokio-tcp/src/incoming.rs +++ b/tokio-tcp/src/incoming.rs @@ -1,5 +1,6 @@ use super::TcpListener; use super::TcpStream; +use futures_core::ready; use futures_core::stream::Stream; use std::io; use std::pin::Pin; diff --git a/tokio-tcp/src/lib.rs b/tokio-tcp/src/lib.rs index d50e4b6e..3a8e04b3 100644 --- a/tokio-tcp/src/lib.rs +++ b/tokio-tcp/src/lib.rs @@ -23,15 +23,6 @@ //! [incoming_method]: struct.TcpListener.html#method.incoming //! [`Incoming`]: struct.Incoming.html -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - #[cfg(feature = "incoming")] mod incoming; mod listener; diff --git a/tokio-tcp/src/listener.rs b/tokio-tcp/src/listener.rs index 50621d00..8fa1b4bc 100644 --- a/tokio-tcp/src/listener.rs +++ b/tokio-tcp/src/listener.rs @@ -1,6 +1,7 @@ #[cfg(feature = "incoming")] use super::incoming::Incoming; use super::TcpStream; +use futures_core::ready; use mio; use std::convert::TryFrom; use std::fmt; diff --git a/tokio-tcp/src/stream.rs b/tokio-tcp/src/stream.rs index f2253a5e..e621f870 100644 --- a/tokio-tcp/src/stream.rs +++ b/tokio-tcp/src/stream.rs @@ -1,5 +1,6 @@ use crate::split::{split, TcpStreamReadHalf, TcpStreamWriteHalf}; use bytes::{Buf, BufMut}; +use futures_core::ready; use iovec::IoVec; use mio; use std::convert::TryFrom; diff --git a/tokio-test/Cargo.toml b/tokio-test/Cargo.toml index 95e94896..92573a83 100644 --- a/tokio-test/Cargo.toml +++ b/tokio-test/Cargo.toml @@ -28,6 +28,7 @@ tokio-executor = { version = "0.2.0", path = "../tokio-executor" } tokio-io = { version = "0.2.0", path = "../tokio-io" } tokio-sync = { version = "0.2.0", path = "../tokio-sync" } tokio-timer = { version = "0.3.0", path = "../tokio-timer" } +futures-core-preview = "0.3.0-alpha.17" [dev-dependencies] tokio = { path = "../tokio" } diff --git a/tokio-test/src/io.rs b/tokio-test/src/io.rs index 568a81fc..881ffe1a 100644 --- a/tokio-test/src/io.rs +++ b/tokio-test/src/io.rs @@ -20,6 +20,7 @@ use std::task::{self, Poll, Waker}; use std::time::{Duration, Instant}; use std::{cmp, io}; +use futures_core::ready; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_sync::mpsc; use tokio_timer::{clock, timer, Delay}; diff --git a/tokio-test/src/lib.rs b/tokio-test/src/lib.rs index 00d38897..7cfd428c 100644 --- a/tokio-test/src/lib.rs +++ b/tokio-test/src/lib.rs @@ -20,15 +20,6 @@ //! assert_ready!(fut.poll()); //! ``` -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - pub mod clock; pub mod io; mod macros; diff --git a/tokio-threadpool/Cargo.toml b/tokio-threadpool/Cargo.toml index cb3b454a..e4f90c7a 100644 --- a/tokio-threadpool/Cargo.toml +++ b/tokio-threadpool/Cargo.toml @@ -25,6 +25,7 @@ publish = false [dependencies] tokio-executor = { version = "0.2.0", path = "../tokio-executor" } tokio-sync = { version = "0.2.0", path = "../tokio-sync" } +futures-core-preview = "0.3.0-alpha.17" arc-waker = { git = "https://github.com/tokio-rs/async" } crossbeam-deque = "0.7.0" diff --git a/tokio-threadpool/src/blocking.rs b/tokio-threadpool/src/blocking.rs index c50a28ac..72028836 100644 --- a/tokio-threadpool/src/blocking.rs +++ b/tokio-threadpool/src/blocking.rs @@ -1,5 +1,6 @@ use crate::worker::Worker; +use futures_core::ready; use std::error::Error; use std::fmt; use std::task::Poll; diff --git a/tokio-threadpool/src/lib.rs b/tokio-threadpool/src/lib.rs index dcf95933..888dbe8c 100644 --- a/tokio-threadpool/src/lib.rs +++ b/tokio-threadpool/src/lib.rs @@ -131,15 +131,6 @@ pub mod park; -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - mod blocking; mod builder; mod callback; diff --git a/tokio-threadpool/tests/blocking.rs b/tokio-threadpool/tests/blocking.rs index e5ef81a6..01259481 100644 --- a/tokio-threadpool/tests/blocking.rs +++ b/tokio-threadpool/tests/blocking.rs @@ -5,6 +5,7 @@ use tokio_test::*; use tokio_threadpool::*; use async_util::future::poll_fn; +use futures_core::ready; use rand::*; use std::sync::atomic::Ordering::*; use std::sync::atomic::*; @@ -13,15 +14,6 @@ use std::task::{Poll, Waker}; use std::thread; use std::time::Duration; -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - #[test] fn basic() { let _ = ::env_logger::try_init(); diff --git a/tokio-timer/Cargo.toml b/tokio-timer/Cargo.toml index e6e5853a..5cdbaa49 100644 --- a/tokio-timer/Cargo.toml +++ b/tokio-timer/Cargo.toml @@ -22,18 +22,18 @@ Timer facilities for Tokio publish = false [features] -async-traits = ["futures-core-preview"] +async-traits = [] [dependencies] tokio-executor = { version = "0.2.0", path = "../tokio-executor" } tokio-sync = { version = "0.2.0", path = "../tokio-sync" } +futures-core-preview = "0.3.0-alpha.17" async-util = { git = "https://github.com/tokio-rs/async" } crossbeam-utils = "0.6.0" # Backs `DelayQueue` slab = "0.4.1" # optionals -futures-core-preview = { version = "0.3.0-alpha.17", optional = true } [dev-dependencies] rand = "0.7" diff --git a/tokio-timer/src/delay.rs b/tokio-timer/src/delay.rs index 7411e071..41210690 100644 --- a/tokio-timer/src/delay.rs +++ b/tokio-timer/src/delay.rs @@ -1,4 +1,5 @@ use crate::timer::{HandlePriv, Registration}; +use futures_core::ready; use std::future::Future; use std::pin::Pin; use std::task::{self, Poll}; diff --git a/tokio-timer/src/delay_queue.rs b/tokio-timer/src/delay_queue.rs index 79b1d29f..d9d0f36c 100644 --- a/tokio-timer/src/delay_queue.rs +++ b/tokio-timer/src/delay_queue.rs @@ -9,6 +9,7 @@ use crate::timer::Handle; use crate::wheel::{self, Wheel}; use crate::{Delay, Error}; +use futures_core::ready; use slab::Slab; use std::cmp; use std::future::Future; diff --git a/tokio-timer/src/interval.rs b/tokio-timer/src/interval.rs index e112d07a..f0448640 100644 --- a/tokio-timer/src/interval.rs +++ b/tokio-timer/src/interval.rs @@ -1,6 +1,7 @@ use crate::clock; use crate::Delay; +use futures_core::ready; use std::future::Future; use std::pin::Pin; use std::task::{self, Poll}; diff --git a/tokio-timer/src/lib.rs b/tokio-timer/src/lib.rs index 48b9ba00..36449472 100644 --- a/tokio-timer/src/lib.rs +++ b/tokio-timer/src/lib.rs @@ -32,15 +32,6 @@ //! [`Interval`]: struct.Interval.html //! [`Timer`]: timer/struct.Timer.html -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(v) => v, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - pub mod clock; pub mod delay_queue; #[cfg(feature = "async-traits")] diff --git a/tokio-timer/src/throttle.rs b/tokio-timer/src/throttle.rs index 494c42cc..dae09320 100644 --- a/tokio-timer/src/throttle.rs +++ b/tokio-timer/src/throttle.rs @@ -1,6 +1,7 @@ //! Slow down a stream by enforcing a delay between items. use crate::{clock, Delay}; +use futures_core::ready; use futures_core::Stream; use std::{ future::Future, diff --git a/tokio-timer/src/timeout.rs b/tokio-timer/src/timeout.rs index a8ce0d52..18068778 100644 --- a/tokio-timer/src/timeout.rs +++ b/tokio-timer/src/timeout.rs @@ -6,6 +6,8 @@ use crate::clock::now; use crate::Delay; +#[cfg(feature = "async-traits")] +use futures_core::ready; use std::fmt; use std::future::Future; use std::pin::Pin; diff --git a/tokio-udp/Cargo.toml b/tokio-udp/Cargo.toml index d3dc66d8..2af96b5d 100644 --- a/tokio-udp/Cargo.toml +++ b/tokio-udp/Cargo.toml @@ -28,6 +28,7 @@ tokio-reactor = { version = "0.2.0", path = "../tokio-reactor" } # bytes = "0.4" mio = "0.6.14" log = "0.4" +futures-core-preview = "0.3.0-alpha.17" [dev-dependencies] env_logger = { version = "0.5", default-features = false } diff --git a/tokio-udp/src/lib.rs b/tokio-udp/src/lib.rs index 2fe90a8f..13ffeeec 100644 --- a/tokio-udp/src/lib.rs +++ b/tokio-udp/src/lib.rs @@ -12,15 +12,6 @@ //! Reading and writing to it can be done using futures, which return the //! [`Recv`], [`Send`], [`RecvFrom`] and [`SendTo`] structs respectively. -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - // mod frame; mod recv; mod recv_from; diff --git a/tokio-udp/src/socket.rs b/tokio-udp/src/socket.rs index 55648a42..6cbec5f8 100644 --- a/tokio-udp/src/socket.rs +++ b/tokio-udp/src/socket.rs @@ -1,5 +1,6 @@ use super::split::{split, UdpSocketRecvHalf, UdpSocketSendHalf}; use super::{Recv, RecvFrom, Send, SendTo}; +use futures_core::ready; use mio; use std::convert::TryFrom; use std::fmt; diff --git a/tokio-uds/Cargo.toml b/tokio-uds/Cargo.toml index 2d941ec4..8a4437dc 100644 --- a/tokio-uds/Cargo.toml +++ b/tokio-uds/Cargo.toml @@ -22,11 +22,11 @@ categories = ["asynchronous"] publish = false [features] -async-traits = ["futures-core-preview"] +async-traits = [] [dependencies] bytes = "0.4.8" -futures-core-preview = { version = "0.3.0-alpha.17", optional = true } +futures-core-preview = { version = "0.3.0-alpha.17" } iovec = "0.1.2" libc = "0.2.42" log = "0.4.2" diff --git a/tokio-uds/src/datagram.rs b/tokio-uds/src/datagram.rs index 87d1d49b..6213a625 100644 --- a/tokio-uds/src/datagram.rs +++ b/tokio-uds/src/datagram.rs @@ -1,4 +1,5 @@ use crate::{Recv, RecvFrom, Send, SendTo}; +use futures_core::ready; use mio::Ready; use mio_uds; use std::fmt; diff --git a/tokio-uds/src/incoming.rs b/tokio-uds/src/incoming.rs index 1a16302a..0bdbcad5 100644 --- a/tokio-uds/src/incoming.rs +++ b/tokio-uds/src/incoming.rs @@ -1,6 +1,7 @@ #![cfg(feature = "async-traits")] use crate::{UnixListener, UnixStream}; +use futures_core::ready; use futures_core::stream::Stream; use std::io; use std::pin::Pin; diff --git a/tokio-uds/src/lib.rs b/tokio-uds/src/lib.rs index fef2a5c5..9ea1135b 100644 --- a/tokio-uds/src/lib.rs +++ b/tokio-uds/src/lib.rs @@ -8,15 +8,6 @@ //! //! This crate provides APIs for using Unix Domain Sockets with Tokio. -macro_rules! ready { - ($e:expr) => { - match $e { - ::std::task::Poll::Ready(t) => t, - ::std::task::Poll::Pending => return ::std::task::Poll::Pending, - } - }; -} - mod datagram; // mod frame; mod incoming; diff --git a/tokio-uds/src/listener.rs b/tokio-uds/src/listener.rs index e875344a..17c50305 100644 --- a/tokio-uds/src/listener.rs +++ b/tokio-uds/src/listener.rs @@ -1,4 +1,5 @@ use crate::UnixStream; +use futures_core::ready; use mio::Ready; use mio_uds; use std::convert::TryFrom; diff --git a/tokio-uds/src/stream.rs b/tokio-uds/src/stream.rs index dfaa4fd9..7d13245f 100644 --- a/tokio-uds/src/stream.rs +++ b/tokio-uds/src/stream.rs @@ -1,5 +1,6 @@ use crate::ucred::{self, UCred}; use bytes::{Buf, BufMut}; +use futures_core::ready; use iovec::IoVec; use mio::Ready; use mio_uds; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 52bee83c..3eaeff97 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -62,6 +62,7 @@ uds = ["tokio-uds"] [dependencies] # Only non-optional dependency... #futures = "0.1.20" +futures-core-preview = "0.3.0-alpha.17" # Everything else is optional... bytes = { version = "0.4", optional = true } diff --git a/tokio/src/io/copy.rs b/tokio/src/io/copy.rs index cc8e71dd..a324cbf8 100644 --- a/tokio/src/io/copy.rs +++ b/tokio/src/io/copy.rs @@ -1,3 +1,4 @@ +use futures_core::ready; use std::future::Future; use std::io; use std::pin::Pin; diff --git a/tokio/src/io/read_exact.rs b/tokio/src/io/read_exact.rs index 32320814..82b95362 100644 --- a/tokio/src/io/read_exact.rs +++ b/tokio/sr |