From cb4aea394e6851ae8cc45a68beeaf2c93cc9a0c0 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 14 May 2019 10:27:36 -0700 Subject: Update Tokio to Rust 2018 (#1082) --- CONTRIBUTING.md | 4 - README.md | 2 - async-await/Cargo.toml | 20 +- async-await/src/chat.rs | 14 +- async-await/src/echo_client.rs | 10 +- async-await/src/echo_server.rs | 8 +- async-await/src/hyper.rs | 6 +- async-await/tests/macros.rs | 4 +- azure-pipelines.yml | 8 +- benches/latency.rs | 115 ------- benches/mio-ops.rs | 57 ---- benches/tcp.rs | 261 --------------- ci/azure-tsan.yml | 2 +- ci/tsan | 2 + tokio-buf/Cargo.toml | 6 +- tokio-buf/README.md | 8 +- tokio-buf/src/lib.rs | 17 +- tokio-buf/src/never.rs | 4 +- tokio-buf/src/str.rs | 6 +- tokio-buf/src/u8.rs | 4 +- tokio-buf/src/util/chain.rs | 4 +- tokio-buf/src/util/collect.rs | 4 +- tokio-buf/src/util/from.rs | 6 +- tokio-buf/src/util/iter.rs | 4 +- tokio-buf/src/util/limit.rs | 2 +- tokio-buf/src/util/mod.rs | 2 +- tokio-buf/src/util/stream.rs | 2 +- tokio-buf/tests/buf_stream.rs | 4 +- tokio-buf/tests/chain.rs | 6 - tokio-buf/tests/collect.rs | 6 - tokio-buf/tests/iter.rs | 5 - tokio-buf/tests/limit.rs | 6 - tokio-buf/tests/size_hint.rs | 2 - tokio-buf/tests/stream.rs | 6 - tokio-buf/tests/string.rs | 5 - tokio-buf/tests/support.rs | 7 +- tokio-codec/Cargo.toml | 8 +- tokio-codec/README.md | 15 - tokio-codec/src/lib.rs | 12 +- tokio-codec/tests/codecs.rs | 3 +- tokio-codec/tests/framed.rs | 5 +- tokio-codec/tests/framed_read.rs | 11 +- tokio-codec/tests/framed_write.rs | 11 +- tokio-current-thread/Cargo.toml | 8 +- tokio-current-thread/src/lib.rs | 66 ++-- tokio-current-thread/src/scheduler.rs | 30 +- tokio-current-thread/tests/current_thread.rs | 44 ++- tokio-executor/Cargo.toml | 8 +- tokio-executor/src/enter.rs | 11 +- tokio-executor/src/error.rs | 2 +- tokio-executor/src/executor.rs | 29 +- tokio-executor/src/global.rs | 19 +- tokio-executor/src/lib.rs | 17 +- tokio-executor/src/park.rs | 7 +- tokio-executor/src/typed.rs | 24 +- tokio-executor/tests/executor.rs | 9 +- tokio-fs/Cargo.toml | 15 +- tokio-fs/examples/std-echo.rs | 7 +- tokio-fs/src/create_dir.rs | 5 +- tokio-fs/src/create_dir_all.rs | 5 +- tokio-fs/src/file/clone.rs | 2 - tokio-fs/src/file/create.rs | 6 +- tokio-fs/src/file/metadata.rs | 6 +- tokio-fs/src/file/mod.rs | 352 +++++++++------------ tokio-fs/src/file/open.rs | 6 +- tokio-fs/src/file/open_options.rs | 1 - tokio-fs/src/file/seek.rs | 4 +- tokio-fs/src/hard_link.rs | 5 +- tokio-fs/src/lib.rs | 46 ++- tokio-fs/src/metadata.rs | 2 - tokio-fs/src/os/unix.rs | 5 +- tokio-fs/src/os/windows/symlink_dir.rs | 5 +- tokio-fs/src/os/windows/symlink_file.rs | 5 +- tokio-fs/src/read.rs | 25 +- tokio-fs/src/read_dir.rs | 91 +++--- tokio-fs/src/read_link.rs | 5 +- tokio-fs/src/remove_dir.rs | 5 +- tokio-fs/src/remove_file.rs | 5 +- tokio-fs/src/rename.rs | 5 +- tokio-fs/src/set_permissions.rs | 5 +- tokio-fs/src/stderr.rs | 8 +- tokio-fs/src/stdin.rs | 5 +- tokio-fs/src/stdout.rs | 8 +- tokio-fs/src/symlink_metadata.rs | 2 - tokio-fs/src/write.rs | 29 +- tokio-fs/tests/dir.rs | 4 +- tokio-fs/tests/file.rs | 14 +- tokio-fs/tests/link.rs | 7 +- tokio-fs/tests/pool/mod.rs | 4 +- tokio-futures/Cargo.toml | 8 +- tokio-futures/README.md | 9 +- tokio-futures/src/async_wait.rs | 15 + tokio-futures/src/await.rs | 16 - tokio-futures/src/compat/forward.rs | 2 +- tokio-futures/src/compat/mod.rs | 2 +- tokio-futures/src/io/flush.rs | 7 +- tokio-futures/src/io/mod.rs | 30 +- tokio-futures/src/io/read.rs | 10 +- tokio-futures/src/io/read_exact.rs | 10 +- tokio-futures/src/io/write.rs | 10 +- tokio-futures/src/io/write_all.rs | 10 +- tokio-futures/src/lib.rs | 15 +- tokio-futures/src/sink/mod.rs | 2 +- tokio-futures/src/sink/send.rs | 8 +- tokio-futures/src/stream/mod.rs | 12 +- tokio-futures/src/stream/next.rs | 5 +- tokio-io/Cargo.toml | 6 +- tokio-io/README.md | 8 +- tokio-io/src/_tokio_codec/decoder.rs | 2 +- tokio-io/src/_tokio_codec/encoder.rs | 2 +- tokio-io/src/_tokio_codec/framed.rs | 12 +- tokio-io/src/_tokio_codec/framed_read.rs | 13 +- tokio-io/src/_tokio_codec/framed_write.rs | 15 +- tokio-io/src/_tokio_codec/mod.rs | 1 - tokio-io/src/allow_std.rs | 4 +- tokio-io/src/async_read.rs | 11 +- tokio-io/src/async_write.rs | 5 +- tokio-io/src/codec/bytes_codec.rs | 2 +- tokio-io/src/codec/decoder.rs | 8 +- tokio-io/src/codec/lines_codec.rs | 2 +- tokio-io/src/codec/mod.rs | 55 ++-- tokio-io/src/framed.rs | 16 +- tokio-io/src/framed_read.rs | 15 +- tokio-io/src/framed_write.rs | 15 +- tokio-io/src/io/copy.rs | 6 +- tokio-io/src/io/flush.rs | 6 +- tokio-io/src/io/mod.rs | 8 +- tokio-io/src/io/read.rs | 6 +- tokio-io/src/io/read_exact.rs | 6 +- tokio-io/src/io/read_to_end.rs | 6 +- tokio-io/src/io/read_until.rs | 6 +- tokio-io/src/io/shutdown.rs | 6 +- tokio-io/src/io/write_all.rs | 6 +- tokio-io/src/length_delimited.rs | 35 +- tokio-io/src/lib.rs | 22 +- tokio-io/src/lines.rs | 6 +- tokio-io/src/split.rs | 12 +- tokio-io/tests/async_read.rs | 7 +- tokio-io/tests/length_delimited.rs | 9 +- tokio-macros/Cargo.toml | 2 +- tokio-macros/src/lib.rs | 5 + tokio-reactor/Cargo.toml | 12 +- tokio-reactor/benches/basic.rs | 8 +- tokio-reactor/src/background.rs | 5 +- tokio-reactor/src/lib.rs | 48 +-- tokio-reactor/src/poll_evented.rs | 17 +- tokio-reactor/src/registration.rs | 7 +- tokio-reactor/src/sharded_rwlock.rs | 16 +- tokio-signal/Cargo.toml | 14 +- tokio-signal/README.md | 4 - tokio-signal/examples/ctrl-c.rs | 9 +- tokio-signal/examples/multiple.rs | 12 +- tokio-signal/examples/sighup-example.rs | 10 +- tokio-signal/src/lib.rs | 69 ++-- tokio-signal/src/unix.rs | 15 +- tokio-signal/src/windows.rs | 19 +- tokio-signal/tests/drop_multi_loop.rs | 5 +- tokio-signal/tests/drop_then_get_a_signal.rs | 5 +- ...dropping_does_not_deregister_other_instances.rs | 5 +- tokio-signal/tests/multi_loop.rs | 8 +- tokio-signal/tests/notify_both.rs | 7 +- tokio-signal/tests/signal.rs | 7 +- tokio-signal/tests/simple.rs | 7 +- tokio-signal/tests/support.rs | 16 +- tokio-signal/tests/twice.rs | 7 +- tokio-sync/Cargo.toml | 8 +- tokio-sync/benches/mpsc.rs | 4 +- tokio-sync/benches/oneshot.rs | 4 +- tokio-sync/src/lib.rs | 12 +- tokio-sync/src/lock.rs | 15 +- tokio-sync/src/loom.rs | 2 +- tokio-sync/src/mpsc/block.rs | 3 +- tokio-sync/src/mpsc/bounded.rs | 19 +- tokio-sync/src/mpsc/chan.rs | 20 +- tokio-sync/src/mpsc/list.rs | 8 +- tokio-sync/src/mpsc/mod.rs | 2 - tokio-sync/src/mpsc/unbounded.rs | 14 +- tokio-sync/src/oneshot.rs | 15 +- tokio-sync/src/semaphore.rs | 12 +- tokio-sync/src/task/atomic_task.rs | 5 +- tokio-sync/src/watch.rs | 23 +- tokio-sync/tests/atomic_task.rs | 6 +- tokio-sync/tests/errors.rs | 4 +- tokio-sync/tests/fuzz_atomic_task.rs | 12 +- tokio-sync/tests/fuzz_list.rs | 6 +- tokio-sync/tests/fuzz_mpsc.rs | 3 +- tokio-sync/tests/fuzz_oneshot.rs | 8 +- tokio-sync/tests/fuzz_semaphore.rs | 10 +- tokio-sync/tests/lock.rs | 7 +- tokio-sync/tests/mpsc.rs | 13 +- tokio-sync/tests/oneshot.rs | 10 +- tokio-sync/tests/semaphore.rs | 7 +- tokio-sync/tests/watch.rs | 5 +- tokio-tcp/Cargo.toml | 12 +- tokio-tcp/src/incoming.rs | 3 +- tokio-tcp/src/lib.rs | 12 +- tokio-tcp/src/listener.rs | 82 ++--- tokio-tcp/src/stream.rs | 163 +++------- tokio-tcp/tests/chain.rs | 9 +- tokio-tcp/tests/echo.rs | 11 +- tokio-tcp/tests/limit.rs | 9 +- tokio-tcp/tests/stream-buffered.rs | 11 +- tokio-tcp/tests/tcp.rs | 10 +- tokio-test/Cargo.toml | 9 +- tokio-test/README.md | 1 - tokio-test/src/clock.rs | 13 +- tokio-test/src/lib.rs | 16 +- tokio-test/src/task.rs | 4 +- tokio-test/tests/clock.rs | 6 +- tokio-threadpool/Cargo.toml | 8 +- tokio-threadpool/README.md | 3 - tokio-threadpool/benches/basic.rs | 8 +- tokio-threadpool/benches/blocking.rs | 16 +- tokio-threadpool/benches/depth.rs | 8 +- tokio-threadpool/src/blocking.rs | 13 +- tokio-threadpool/src/builder.rs | 105 ++---- tokio-threadpool/src/callback.rs | 8 +- tokio-threadpool/src/config.rs | 11 +- tokio-threadpool/src/lib.rs | 30 +- tokio-threadpool/src/notifier.rs | 9 +- tokio-threadpool/src/park/boxed.rs | 8 +- tokio-threadpool/src/park/default_park.rs | 8 +- tokio-threadpool/src/pool/backup.rs | 6 +- tokio-threadpool/src/pool/backup_stack.rs | 2 +- tokio-threadpool/src/pool/mod.rs | 24 +- tokio-threadpool/src/pool/state.rs | 2 +- tokio-threadpool/src/sender.rs | 15 +- tokio-threadpool/src/shutdown.rs | 6 +- tokio-threadpool/src/task/blocking.rs | 10 +- tokio-threadpool/src/task/blocking_state.rs | 5 +- tokio-threadpool/src/task/mod.rs | 12 +- tokio-threadpool/src/thread_pool.rs | 18 +- tokio-threadpool/src/worker/entry.rs | 22 +- tokio-threadpool/src/worker/mod.rs | 20 +- tokio-threadpool/src/worker/stack.rs | 7 +- tokio-threadpool/src/worker/state.rs | 2 +- tokio-threadpool/tests/blocking.rs | 10 +- tokio-threadpool/tests/hammer.rs | 7 +- tokio-threadpool/tests/threadpool.rs | 25 +- tokio-timer/Cargo.toml | 10 +- tokio-timer/src/clock/clock.rs | 12 +- tokio-timer/src/deadline.rs | 12 +- tokio-timer/src/delay.rs | 6 +- tokio-timer/src/delay_queue.rs | 61 ++-- tokio-timer/src/error.rs | 3 +- tokio-timer/src/interval.rs | 11 +- tokio-timer/src/lib.rs | 25 +- tokio-timer/src/throttle.rs | 10 +- tokio-timer/src/timeout.rs | 22 +- tokio-timer/src/timer/atomic_stack.rs | 3 +- tokio-timer/src/timer/entry.rs | 8 +- tokio-timer/src/timer/handle.rs | 10 +- tokio-timer/src/timer/mod.rs | 22 +- tokio-timer/src/timer/now.rs | 2 +- tokio-timer/src/timer/registration.rs | 8 +- tokio-timer/src/timer/stack.rs | 3 +- tokio-timer/src/wheel/level.rs | 5 +- tokio-timer/tests/clock.rs | 7 +- tokio-timer/tests/deadline.rs | 10 +- tokio-timer/tests/delay.rs | 13 +- tokio-timer/tests/hammer.rs | 12 +- tokio-timer/tests/interval.rs | 10 +- tokio-timer/tests/queue.rs | 13 +- tokio-timer/tests/support/mod.rs | 4 + tokio-timer/tests/throttle.rs | 7 +- tokio-timer/tests/timeout.rs | 10 +- tokio-tls/Cargo.toml | 10 +- tokio-tls/README.md | 3 - tokio-tls/examples/download-rust-lang.rs | 15 +- tokio-tls/examples/echo.rs | 11 +- tokio-tls/src/lib.rs | 14 +- tokio-tls/tests/bad.rs | 27 +- tokio-tls/tests/google.rs | 23 +- tokio-tls/tests/smoke.rs | 32 +- tokio-udp/Cargo.toml | 12 +- tokio-udp/src/frame.rs | 10 +- tokio-udp/src/lib.rs | 14 +- tokio-udp/src/recv_dgram.rs | 19 +- tokio-udp/src/send_dgram.rs | 4 +- tokio-udp/src/socket.rs | 9 +- tokio-udp/tests/udp.rs | 24 +- tokio-uds/Cargo.toml | 14 +- tokio-uds/src/datagram.rs | 11 +- tokio-uds/src/frame.rs | 10 +- tokio-uds/src/incoming.rs | 6 +- tokio-uds/src/lib.rs | 33 +- tokio-uds/src/listener.rs | 11 +- tokio-uds/src/recv_dgram.rs | 6 +- tokio-uds/src/send_dgram.rs | 6 +- tokio-uds/src/stream.rs | 11 +- tokio-uds/src/ucred.rs | 9 +- tokio-uds/tests/datagram.rs | 20 +- tokio-uds/tests/stream.rs | 15 +- tokio/Cargo.toml | 33 +- tokio/README.md | 2 - tokio/benches/latency.rs | 113 +++++++ tokio/benches/mio-ops.rs | 56 ++++ tokio/benches/tcp.rs | 256 +++++++++++++++ tokio/examples/blocking.rs | 4 +- tokio/examples/chat-combinator-current-thread.rs | 17 +- tokio/examples/chat-combinator.rs | 16 +- tokio/examples/chat.rs | 18 +- tokio/examples/connect.rs | 25 +- tokio/examples/echo-udp.rs | 11 +- tokio/examples/echo.rs | 12 +- tokio/examples/hello_world.rs | 7 +- tokio/examples/manual-runtime.rs | 16 +- tokio/examples/print_each_packet.rs | 13 +- tokio/examples/proxy.rs | 8 +- tokio/examples/tinydb.rs | 8 +- tokio/examples/tinyhttp.rs | 33 +- tokio/examples/udp-client.rs | 7 +- tokio/examples/udp-codec.rs | 12 +- tokio/src/async_await.rs | 4 +- tokio/src/codec/length_delimited.rs | 39 +-- tokio/src/codec/mod.rs | 7 +- tokio/src/executor/current_thread/mod.rs | 6 +- tokio/src/executor/mod.rs | 4 +- tokio/src/lib.rs | 53 +--- tokio/src/prelude.rs | 12 +- tokio/src/reactor/mod.rs | 9 +- tokio/src/reactor/poll_evented.rs | 12 +- tokio/src/runtime/current_thread/async_await.rs | 2 +- tokio/src/runtime/current_thread/builder.rs | 9 +- tokio/src/runtime/current_thread/mod.rs | 2 - tokio/src/runtime/current_thread/runtime.rs | 21 +- tokio/src/runtime/mod.rs | 9 +- tokio/src/runtime/threadpool/async_await.rs | 2 +- tokio/src/runtime/threadpool/builder.rs | 37 +-- tokio/src/runtime/threadpool/mod.rs | 19 +- tokio/src/runtime/threadpool/shutdown.rs | 8 +- tokio/src/runtime/threadpool/task_executor.rs | 18 +- tokio/src/timer.rs | 6 +- tokio/src/util/enumerate.rs | 2 +- tokio/src/util/future.rs | 9 +- tokio/src/util/stream.rs | 9 +- tokio/tests/buffered.rs | 11 +- tokio/tests/clock.rs | 12 +- tokio/tests/drop-core.rs | 8 +- tokio/tests/enumerate.rs | 5 +- tokio/tests/global.rs | 11 +- tokio/tests/length_delimited.rs | 10 +- tokio/tests/line-frames.rs | 14 +- tokio/tests/pipe-hup.rs | 20 +- tokio/tests/reactor.rs | 17 +- tokio/tests/runtime.rs | 28 +- tokio/tests/timer.rs | 12 +- 347 files changed, 2148 insertions(+), 3236 deletions(-) delete mode 100644 benches/latency.rs delete mode 100644 benches/mio-ops.rs delete mode 100644 benches/tcp.rs create mode 100644 tokio-futures/src/async_wait.rs delete mode 100644 tokio-futures/src/await.rs create mode 100644 tokio/benches/latency.rs create mode 100644 tokio/benches/mio-ops.rs create mode 100644 tokio/benches/tcp.rs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 580be1a4..da207a2b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -153,8 +153,6 @@ The type level example for `tokio_timer::Timeout` provides a good example of a documentation test: ``` -/// # extern crate futures; -/// # extern crate tokio; /// // import the `timeout` function, usually this is done /// // with `use tokio::prelude::*` /// use tokio::prelude::FutureExt; @@ -192,8 +190,6 @@ If this were a documentation test for the `Timeout::new` function, then the example would explicitly use `Timeout::new`. For example: ``` -/// # extern crate futures; -/// # extern crate tokio; /// use tokio::timer::Timeout; /// use futures::Future; /// use futures::sync::oneshot; diff --git a/README.md b/README.md index 9aff6837..20f5bf18 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,6 @@ an asynchronous application. A basic TCP echo server with Tokio: ```rust -extern crate tokio; - use tokio::prelude::*; use tokio::io::copy; use tokio::net::TcpListener; diff --git a/async-await/Cargo.toml b/async-await/Cargo.toml index e605da60..52933b28 100644 --- a/async-await/Cargo.toml +++ b/async-await/Cargo.toml @@ -25,25 +25,7 @@ name = "hyper" path = "src/hyper.rs" [dependencies] -tokio = { version = "0.1.18", features = ["async-await-preview"] } +tokio = { version = "0.2.0", features = ["async-await-preview"], path = "../tokio" } futures = "0.1.23" bytes = "0.4.9" hyper = "0.12.8" - -# Avoid using crates.io for Tokio dependencies -[patch.crates-io] -tokio = { path = "../tokio" } -tokio-codec = { path = "../tokio-codec" } -tokio-current-thread = { path = "../tokio-current-thread" } -tokio-executor = { path = "../tokio-executor" } -tokio-fs = { path = "../tokio-fs" } -tokio-futures = { path = "../tokio-futures" } -tokio-io = { path = "../tokio-io" } -tokio-reactor = { path = "../tokio-reactor" } -tokio-signal = { path = "../tokio-signal" } -tokio-tcp = { path = "../tokio-tcp" } -tokio-threadpool = { path = "../tokio-threadpool" } -tokio-timer = { path = "../tokio-timer" } -tokio-tls = { path = "../tokio-tls" } -tokio-udp = { path = "../tokio-udp" } -tokio-uds = { path = "../tokio-uds" } diff --git a/async-await/src/chat.rs b/async-await/src/chat.rs index d0576f52..d3a0c992 100644 --- a/async-await/src/chat.rs +++ b/async-await/src/chat.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::codec::{LinesCodec, Decoder}; use tokio::net::{TcpListener, TcpStream}; use tokio::prelude::*; @@ -33,7 +33,7 @@ async fn process(stream: TcpStream, state: Arc>) -> io::Result<()> let mut lines = LinesCodec::new().framed(stream); // Extract the peer's name - let name = match await!(lines.next()) { + let name = match async_wait!(lines.next()) { Some(name) => name?, None => { // Disconnected early @@ -56,15 +56,15 @@ async fn process(stream: TcpStream, state: Arc>) -> io::Result<()> // Spawn a task that receives all lines broadcasted to us from other peers // and writes it to the client. tokio::spawn_async(async move { - while let Some(line) = await!(rx.next()) { + while let Some(line) = async_wait!(rx.next()) { let line = line.unwrap(); - await!(lines_tx.send_async(line)).unwrap(); + async_wait!(lines_tx.send_async(line)).unwrap(); } }); // Use the current task to read lines from the socket and broadcast them to // other peers. - while let Some(message) = await!(lines_rx.next()) { + while let Some(message) = async_wait!(lines_rx.next()) { // TODO: Error handling let message = message.unwrap(); @@ -113,7 +113,7 @@ async fn main() { // Start the Tokio runtime. let mut incoming = listener.incoming(); - while let Some(stream) = await!(incoming.next()) { + while let Some(stream) = async_wait!(incoming.next()) { let stream = match stream { Ok(stream) => stream, Err(_) => continue, @@ -122,7 +122,7 @@ async fn main() { let state = state.clone(); tokio::spawn_async(async move { - if let Err(_) = await!(process(stream, state)) { + if let Err(_) = async_wait!(process(stream, state)) { eprintln!("failed to process connection"); } }); diff --git a/async-await/src/echo_client.rs b/async-await/src/echo_client.rs index 7cab4932..302b7ea2 100644 --- a/async-await/src/echo_client.rs +++ b/async-await/src/echo_client.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::net::TcpStream; use tokio::prelude::*; @@ -14,7 +14,7 @@ const MESSAGES: &[&str] = &[ ]; async fn run_client(addr: &SocketAddr) -> io::Result<()> { - let mut stream = await!(TcpStream::connect(addr))?; + let mut stream = async_wait!(TcpStream::connect(addr))?; // Buffer to read into let mut buf = [0; 128]; @@ -23,10 +23,10 @@ async fn run_client(addr: &SocketAddr) -> io::Result<()> { println!(" > write = {:?}", msg); // Write the message to the server - await!(stream.write_all_async(msg.as_bytes()))?; + async_wait!(stream.write_all_async(msg.as_bytes()))?; // Read the message back from the server - await!(stream.read_exact_async(&mut buf[..msg.len()]))?; + async_wait!(stream.read_exact_async(&mut buf[..msg.len()]))?; assert_eq!(&buf[..msg.len()], msg.as_bytes()); } @@ -43,7 +43,7 @@ async fn main() { // Connect to the echo serveer - match await!(run_client(&addr)) { + match async_wait!(run_client(&addr)) { Ok(_) => println!("done."), Err(e) => eprintln!("echo client failed; error = {:?}", e), } diff --git a/async-await/src/echo_server.rs b/async-await/src/echo_server.rs index d282ad6b..63e10e31 100644 --- a/async-await/src/echo_server.rs +++ b/async-await/src/echo_server.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::net::{TcpListener, TcpStream}; use tokio::prelude::*; @@ -11,11 +11,11 @@ fn handle(mut stream: TcpStream) { let mut buf = [0; 1024]; loop { - match await!(stream.read_async(&mut buf)).unwrap() { + match async_wait!(stream.read_async(&mut buf)).unwrap() { 0 => break, // Socket closed n => { // Send the data back - await!(stream.write_all_async(&buf[0..n])).unwrap(); + async_wait!(stream.write_all_async(&buf[0..n])).unwrap(); } } } @@ -35,7 +35,7 @@ async fn main() { let mut incoming = listener.incoming(); - while let Some(stream) = await!(incoming.next()) { + while let Some(stream) = async_wait!(incoming.next()) { let stream = stream.unwrap(); handle(stream); } diff --git a/async-await/src/hyper.rs b/async-await/src/hyper.rs index c86481b4..37332ee4 100644 --- a/async-await/src/hyper.rs +++ b/async-await/src/hyper.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::prelude::*; use hyper::Client; @@ -13,7 +13,7 @@ async fn main() { let uri = "http://httpbin.org/ip".parse().unwrap(); - let response = await!({ + let response = async_wait!({ client.get(uri) .timeout(Duration::from_secs(10)) }).unwrap(); @@ -22,7 +22,7 @@ async fn main() { let mut body = response.into_body(); - while let Some(chunk) = await!(body.next()) { + while let Some(chunk) = async_wait!(body.next()) { let chunk = chunk.unwrap(); println!("chunk = {}", str::from_utf8(&chunk[..]).unwrap()); } diff --git a/async-await/tests/macros.rs b/async-await/tests/macros.rs index 285e5538..1fcbf77b 100644 --- a/async-await/tests/macros.rs +++ b/async-await/tests/macros.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::timer::Delay; use std::time::{Duration, Instant}; @@ -18,5 +18,5 @@ async fn fail_no_async() { #[tokio::test] async fn use_timer() { let when = Instant::now() + Duration::from_millis(10); - await!(Delay::new(when)); + async_wait!(Delay::new(when)); } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3be914e2..1ad71db8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,6 +1,9 @@ trigger: ["master"] pr: ["master"] +variables: + nightly: nightly-2019-05-09 + jobs: # Check formatting - template: ci/azure-rustfmt.yml @@ -76,7 +79,7 @@ jobs: parameters: name: test_nightly displayName: Test Async / Await - rust: nightly-2019-04-25 + rust: $(nightly) # Try cross compiling - template: ci/azure-cross-compile.yml @@ -94,11 +97,12 @@ jobs: - template: ci/azure-check-minrust.yml parameters: name: minrust - rust_version: 1.26.0 + rust_version: 1.34.0 - template: ci/azure-tsan.yml parameters: name: tsan + rust: $(nightly) - template: ci/azure-deploy-docs.yml parameters: diff --git a/benches/latency.rs b/benches/latency.rs deleted file mode 100644 index d9ace03a..00000000 --- a/benches/latency.rs +++ /dev/null @@ -1,115 +0,0 @@ -#![feature(test)] -#![deny(warnings)] - -extern crate test; -#[macro_use] -extern crate futures; -extern crate tokio; - -use std::io; -use std::net::SocketAddr; -use std::thread; - -use futures::sync::mpsc; -use futures::sync::oneshot; -use futures::{Future, Poll, Sink, Stream}; -use test::Bencher; -use tokio::net::UdpSocket; - -/// UDP echo server -struct EchoServer { - socket: UdpSocket, - buf: Vec, - to_send: Option<(usize, SocketAddr)>, -} - -impl EchoServer { - fn new(s: UdpSocket) -> Self { - EchoServer { - socket: s, - to_send: None, - buf: vec![0u8; 1600], - } - } -} - -impl Future for EchoServer { - type Item = (); - type Error = io::Error; - - fn poll(&mut self) -> Poll<(), io::Error> { - loop { - if let Some(&(size, peer)) = self.to_send.as_ref() { - try_ready!(self.socket.poll_send_to(&self.buf[..size], &peer)); - self.to_send = None; - } - self.to_send = Some(try_ready!(self.socket.poll_recv_from(&mut self.buf))); - } - } -} - -#[bench] -fn udp_echo_latency(b: &mut Bencher) { - let any_addr = "127.0.0.1:0".to_string(); - let any_addr = any_addr.parse::().unwrap(); - - let (stop_c, stop_p) = oneshot::channel::<()>(); - let (tx, rx) = oneshot::channel(); - - let child = thread::spawn(move || { - let socket = tokio::net::UdpSocket::bind(&any_addr).unwrap(); - tx.send(socket.local_addr().unwrap()).unwrap(); - - let server = EchoServer::new(socket); - let server = server.select(stop_p.map_err(|_| panic!())); - let server = server.map_err(|_| ()); - server.wait().unwrap(); - }); - - let client = std::net::UdpSocket::bind(&any_addr).unwrap(); - - let server_addr = rx.wait().unwrap(); - let mut buf = [0u8; 1000]; - - // warmup phase; for some reason initial couple of - // runs are much slower - // - // TODO: Describe the exact reasons; caching? branch predictor? lazy closures? - for _ in 0..8 { - client.send_to(&buf, &server_addr).unwrap(); - let _ = client.recv_from(&mut buf).unwrap(); - } - - b.iter(|| { - client.send_to(&buf, &server_addr).unwrap(); - let _ = client.recv_from(&mut buf).unwrap(); - }); - - stop_c.send(()).unwrap(); - child.join().unwrap(); -} - -#[bench] -fn futures_channel_latency(b: &mut Bencher) { - let (mut in_tx, in_rx) = mpsc::channel(32); - let (out_tx, out_rx) = mpsc::channel::<_>(32); - - let child = thread::spawn(|| out_tx.send_all(in_rx.then(|r| r.unwrap())).wait()); - let mut rx_iter = out_rx.wait(); - - // warmup phase; for some reason initial couple of runs are much slower - // - // TODO: Describe the exact reasons; caching? branch predictor? lazy closures? - for _ in 0..8 { - in_tx.start_send(Ok(1usize)).unwrap(); - let _ = rx_iter.next(); - } - - b.iter(|| { - in_tx.start_send(Ok(1usize)).unwrap(); - let _ = rx_iter.next(); - }); - - drop(in_tx); - child.join().unwrap().unwrap(); -} diff --git a/benches/mio-ops.rs b/benches/mio-ops.rs deleted file mode 100644 index be4db7f7..00000000 --- a/benches/mio-ops.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Measure cost of different operations -// to get a sense of performance tradeoffs -#![feature(test)] -#![deny(warnings)] - -extern crate mio; -extern crate test; - -use test::Bencher; - -use mio::tcp::TcpListener; -use mio::{PollOpt, Ready, Token}; - -#[bench] -fn mio_register_deregister(b: &mut Bencher) { - let addr = "127.0.0.1:0".parse().unwrap(); - // Setup the server socket - let sock = TcpListener::bind(&addr).unwrap(); - let poll = mio::Poll::new().unwrap(); - - const CLIENT: Token = Token(1); - - b.iter(|| { - poll.register(&sock, CLIENT, Ready::readable(), PollOpt::edge()) - .unwrap(); - poll.deregister(&sock).unwrap(); - }); -} - -#[bench] -fn mio_reregister(b: &mut Bencher) { - let addr = "127.0.0.1:0".parse().unwrap(); - // Setup the server socket - let sock = TcpListener::bind(&addr).unwrap(); - let poll = mio::Poll::new().unwrap(); - - const CLIENT: Token = Token(1); - poll.register(&sock, CLIENT, Ready::readable(), PollOpt::edge()) - .unwrap(); - - b.iter(|| { - poll.reregister(&sock, CLIENT, Ready::readable(), PollOpt::edge()) - .unwrap(); - }); - poll.deregister(&sock).unwrap(); -} - -#[bench] -fn mio_poll(b: &mut Bencher) { - let poll = mio::Poll::new().unwrap(); - let timeout = std::time::Duration::new(0, 0); - let mut events = mio::Events::with_capacity(1024); - - b.iter(|| { - poll.poll(&mut events, Some(timeout)).unwrap(); - }); -} diff --git a/benches/tcp.rs b/benches/tcp.rs deleted file mode 100644 index 1872790d..00000000 --- a/benches/tcp.rs +++ /dev/null @@ -1,261 +0,0 @@ -#![feature(test)] -#![deny(warnings)] - -extern crate futures; -extern crate tokio; - -#[macro_use] -extern crate tokio_io; - -pub extern crate test; - -mod prelude { - pub use futures::*; - pub use tokio::net::{TcpListener, TcpStream}; - pub use tokio::reactor::Reactor; - pub use tokio_io::io::read_to_end; - - pub use std::io::{self, Read, Write}; - pub use std::thread; - pub use std::time::Duration; - pub use test::{self, Bencher}; -} - -mod connect_churn { - use prelude::*; - - const NUM: usize = 300; - const CONCURRENT: usize = 8; - - #[bench] - fn one_thread(b: &mut Bencher) { - let addr = "127.0.0.1:0".parse().unwrap(); - - b.iter(move || { - let listener = TcpListener::bind(&addr).unwrap(); - let addr = listener.local_addr().unwrap(); - - // Spawn a single future that accepts & drops connections - let serve_incomings = listener - .incoming() - .map_err(|e| panic!("server err: {:?}", e)) - .for_each(|_| Ok(())); - - let connects = stream::iter_result((0..NUM).map(|_| { - Ok(TcpStream::connect(&addr).and_then(|sock| { - sock.set_linger(Some(Duration::from_secs(0))).unwrap(); - read_to_end(sock, vec![]) - })) - })); - - let connects_concurrent = connects - .buffer_unordered(CONCURRENT) - .map_err(|e| panic!("client err: {:?}", e)) - .for_each(|_| Ok(())); - - serve_incomings - .select(connects_concurrent) - .map(|_| ()) - .map_err(|_| ()) - .wait() - .unwrap(); - }); - } - - fn n_workers(n: usize, b: &mut Bencher) { - let (shutdown_tx, shutdown_rx) = sync::oneshot::channel(); - let (addr_tx, addr_rx) = sync::oneshot::channel(); - - // Spawn reactor thread - let server_thread = thread::spawn(move || { - // Bind the TCP listener - let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap()).unwrap(); - - // Get the address being listened on. - let addr = listener.local_addr().unwrap(); - - // Send the remote & address back to the main thread - addr_tx.send(addr).unwrap(); - - // Spawn a single future that accepts & drops connections - let serve_incomings = listener - .incoming() - .map_err(|e| panic!("server err: {:?}", e)) - .for_each(|_| Ok(())); - - // Run server - serve_incomings - .select(shutdown_rx) - .map(|_| ()) - .map_err(|_| ()) - .wait() - .unwrap(); - }); - - // Get the bind addr of the server - let addr = addr_rx.wait().unwrap(); - - b.iter(move || { - use std::sync::{Arc, Barrier}; - - // Create a barrier to coordinate threads - let barrier = Arc::new(Barrier::new(n + 1)); - - // Spawn worker threads - let threads: Vec<_> = (0..n) - .map(|_| { - let barrier = barrier.clone(); - let addr = addr.clone(); - - thread::spawn(move || { - let connects = stream::iter_result((0..(NUM / n)).map(|_| { - Ok(TcpStream::connect(&addr) - .map_err(|e| panic!("connect err: {:?}", e)) - .and_then(|sock| { - sock.set_linger(Some(Duration::from_secs(0))).unwrap(); - read_to_end(sock, vec![]) - })) - })); - - barrier.wait(); - - connects - .buffer_unordered(CONCURRENT) - .map_err(|e| panic!("client err: {:?}", e)) - .for_each(|_| Ok(())) - .wait() - .unwrap(); - }) - }) - .collect(); - - barrier.wait(); - - for th in threads { - th.join().unwrap(); - } - }); - - // Shutdown the server - shutdown_tx.send(()).unwrap(); - server_thread.join().unwrap(); - } - - #[bench] - fn two_threads(b: &mut Bencher) { - n_workers(1, b); - } - - #[bench] - fn multi_threads(b: &mut Bencher) { - n_workers(4, b); - } -} - -mod transfer { - use prelude::*; - use std::{cmp, mem}; - - const MB: usize = 3 * 1024 * 1024; - - struct Drain { - sock: TcpStream, - chunk: usize, - } - - impl Future for Drain { - type Item = (); - type Error = io::Error; - - fn poll(&mut self) -> Poll<(), io::Error> { - let mut buf: [u8; 1024] = unsafe { mem::uninitialized() }; - - loop { - match try_nb!(self.sock.read(&mut buf[..self.chunk])) { - 0 => return Ok(Async::Ready(())), - _ => {} - } - } - } - } - - struct Transfer { - sock: TcpStream, - rem: usize, - chunk: usize, - } - - impl Future for Transfer { - type Item = (); - type Error = io::Error; - - fn poll(&mut self) -> Poll<(), io::Error> { - while self.rem > 0 { - let len = cmp::min(self.rem, self.chunk); - let buf = &DATA[..len]; - - let n = try_nb!(self.sock.write(&buf)); - self.rem -= n; - } - - Ok(Async::Ready(())) - } - } - - static DATA: [u8; 1024] = [0; 1024]; - - fn one_thread(b: &mut Bencher, read_size: usize, write_size: usize) { - let addr = "127.0.0.1:0".parse().unwrap(); - - b.iter(move || { - let listener = TcpListener::bind(&addr).unwrap(); - let addr = listener.local_addr().unwrap(); - - // Spawn a single future that accepts 1 connection, Drain it and drops - let server = listener - .incoming() - .into_future() // take the first connection - .map_err(|(e, _other_incomings)| e) - .map(|(connection, _other_incomings)| connection.unwrap()) - .and_then(|sock| { - sock.set_linger(Some(Duration::from_secs(0))).unwrap(); - let drain = Drain { - sock: sock, - chunk: read_size, - }; - drain - .map(|_| ()) - .map_err(|e| panic!("server error: {:?}", e)) - }) - .map_err(|e| panic!("server err: {:?}", e)); - - let client = TcpStream::connect(&addr) - .and_then(move |sock| Transfer { - sock: sock, - rem: MB, - chunk: write_size, - }) - .map_err(|e| panic!("client err: {:?}", e)); - - server.join(client).wait().unwrap(); - }); - } - - mod small_chunks { - use prelude::*; - - #[bench] - fn one_thread(b: &mut Bencher) { - super::one_thread(b, 32, 32); - } - } - - mod big_chunks { - use prelude::*; - - #[bench] - fn one_thread(b: &mut Bencher) { - super::one_thread(b, 1_024, 1_024); - } - } -} diff --git a/ci/azure-tsan.yml b/ci/azure-tsan.yml index 519960f3..3666c285 100644 --- a/ci/azure-tsan.yml +++ b/ci/azure-tsan.yml @@ -12,7 +12,7 @@ jobs: steps: - template: azure-install-rust.yml parameters: - rust_version: nightly-2018-11-18 + rust_version: ${{ parameters.rust }} - template: azure-patch-crates.yml - script: | diff --git a/ci/tsan b/ci/tsan index a261830f..3791c270 100644 --- a/ci/tsan +++ b/ci/tsan @@ -8,6 +8,8 @@ race:Weak*drop # `std` mpsc is not used in any Tokio code base. This race is triggered by some # rust runtime logic. race:std*mpsc_queue +race:std*lang_start +race:drop*std::thread* # Probably more fences in std. race:__call_tls_dtors diff --git a/tokio-buf/Cargo.toml b/tokio-buf/Cargo.toml index 2fbe81d2..f9f069ab 100644 --- a/tokio-buf/Cargo.toml +++ b/tokio-buf/Cargo.toml @@ -7,8 +7,9 @@ name = "tokio-buf" # - Cargo.toml # - README.md # - Update CHANGELOG.md. -# - Create "v0.1.x" git tag. -version = "0.1.1" +# - Create "v0.2.x" git tag. +version = "0.2.0" +edition = "2018" authors = ["Carl Lerche "] license = "MIT" repository = "https://github.com/tokio-rs/tokio" @@ -18,6 +19,7 @@ description = """ Asynchronous stream of byte buffers """ categories = ["asynchronous"] +publish = false [dependencies] bytes = "0.4.10" diff --git a/tokio-buf/README.md b/tokio-buf/README.md index d9f3e5e3..f5d939df 100644 --- a/tokio-buf/README.md +++ b/tokio-buf/README.md @@ -6,19 +6,13 @@ Asynchronous stream of byte buffers ## Usage -First, add this to your `Cargo.toml`: +Add this to your `Cargo.toml`: ```toml [dependencies] tokio-buf = "0.1.1" ``` -Next, add this to your crate: - -```rust -extern crate tokio_buf; -``` - You can find extensive documentation and examples about how to use this crate online at [https://tokio.rs](https://tokio.rs). The [API documentation](https://docs.rs/tokio-buf) is also a great place to get started diff --git a/tokio-buf/src/lib.rs b/tokio-buf/src/lib.rs index c07e4025..823bad49 100644 --- a/tokio-buf/src/lib.rs +++ b/tokio-buf/src/lib.rs @@ -1,6 +1,12 @@ #![doc(html_root_url = "https://docs.rs/tokio-buf/0.1.1")] -#![deny(missing_docs, missing_debug_implementations, unreachable_pub)] +#![deny( + missing_docs, + missing_debug_implementations, + unreachable_pub, + rust_2018_idioms +)] #![cfg_attr(test, deny(warnings))] +#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Asynchronous stream of bytes. //! @@ -9,13 +15,6 @@ //! instead of yielding arbitrary values, it only yields types that implement //! `Buf` (i.e, byte collections). -extern crate bytes; -#[cfg(feature = "util")] -extern crate either; -#[allow(unused)] -#[macro_use] -extern crate futures; - mod never; mod size_hint; mod str; @@ -26,7 +25,7 @@ pub mod util; pub use self::size_hint::SizeHint; #[doc(inline)] #[cfg(feature = "util")] -pub use util::BufStreamExt; +pub use crate::util::BufStreamExt; use bytes::Buf; use futures::Poll; diff --git a/tokio-buf/src/never.rs b/tokio-buf/src/never.rs index dcbde39c..e972167b 100644 --- a/tokio-buf/src/never.rs +++ b/tokio-buf/src/never.rs @@ -4,13 +4,13 @@ use std::{error, fmt}; pub enum Never {} impl fmt::Debug for Never { - fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {} } } impl fmt::Display for Never { - fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {} } } diff --git a/tokio-buf/src/str.rs b/tokio-buf/src/str.rs index 8af76950..05327be8 100644 --- a/tokio-buf/src/str.rs +++ b/tokio-buf/src/str.rs @@ -1,6 +1,6 @@ -use never::Never; -use BufStream; -use SizeHint; +use crate::never::Never; +use crate::BufStream; +use crate::SizeHint; use futures::Poll; diff --git a/tokio-buf/src/u8.rs b/tokio-buf/src/u8.rs index 4b1bc58e..5baf9d8e 100644 --- a/tokio-buf/src/u8.rs +++ b/tokio-buf/src/u8.rs @@ -1,8 +1,8 @@ +use crate::never::Never; +use crate::BufStream; use bytes::{Bytes, BytesMut}; use futures::Poll; -use never::Never; use std::io; -use BufStream; impl BufStream for Vec { type Item = io::Cursor>; diff --git a/tokio-buf/src/util/chain.rs b/tokio-buf/src/util/chain.rs index 44fc4008..58e17ca5 100644 --- a/tokio-buf/src/util/chain.rs +++ b/tokio-buf/src/util/chain.rs @@ -1,7 +1,7 @@ -use BufStream; +use crate::BufStream; use either::Either; -use futures::Poll; +use futures::{try_ready, Poll}; /// A buf stream that sequences two buf streams together. /// diff --git a/tokio-buf/src/util/collect.rs b/tokio-buf/src/util/collect.rs index d4bc57e6..5ed0462c 100644 --- a/tokio-buf/src/util/collect.rs +++ b/tokio-buf/src/util/collect.rs @@ -1,7 +1,7 @@ use super::FromBufStream; -use BufStream; +use crate::BufStream; -use futures::{Future, Poll}; +use futures::{try_ready, Future, Poll}; /// Consumes a buf stream, collecting the data into a single byte container. /// diff --git a/tokio-buf/src/util/from.rs b/tokio-buf/src/util/from.rs index debebb16..05f047be 100644 --- a/tokio-buf/src/util/from.rs +++ b/tokio-buf/src/util/from.rs @@ -1,4 +1,4 @@ -use SizeHint; +use crate::SizeHint; use bytes::{Buf, BufMut, Bytes}; @@ -138,7 +138,7 @@ impl FromBufStream for Bytes { } impl fmt::Display for CollectVecError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "BufStream is too big") } } @@ -150,7 +150,7 @@ impl Error for CollectVecError { } impl fmt::Display for CollectBytesError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "BufStream too big") } } diff --git a/tokio-buf/src/util/iter.rs b/tokio-buf/src/util/iter.rs index 0f48546a..dff4d343 100644 --- a/tokio-buf/src/util/iter.rs +++ b/tokio-buf/src/util/iter.rs @@ -1,8 +1,8 @@ +use crate::BufStream; use bytes::Buf; use futures::Poll; use std::error::Error; use std::fmt; -use BufStream; /// Converts an `Iterator` into a `BufStream` which is always ready to yield the /// next value. @@ -42,7 +42,7 @@ where } impl fmt::Display for Never { - fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { unreachable!(); } } diff --git a/tokio-buf/src/util/limit.rs b/tokio-buf/src/util/limit.rs index c89e687a..03c0d913 100644 --- a/tokio-buf/src/util/limit.rs +++ b/tokio-buf/src/util/limit.rs @@ -1,4 +1,4 @@ -use BufStream; +use crate::BufStream; use bytes::Buf; use futures::Poll; diff --git a/tokio-buf/src/util/mod.rs b/tokio-buf/src/util/mod.rs index 14c63183..d6848e88 100644 --- a/tokio-buf/src/util/mod.rs +++ b/tokio-buf/src/util/mod.rs @@ -22,7 +22,7 @@ pub mod error { pub use super::limit::LimitError; } -use BufStream; +use crate::BufStream; impl BufStreamExt for T where T: BufStream {} diff --git a/tokio-buf/src/util/stream.rs b/tokio-buf/src/util/stream.rs index 8716f23b..25af75b3 100644 --- a/tokio-buf/src/util/stream.rs +++ b/tokio-buf/src/util/stream.rs @@ -1,6 +1,6 @@ +use crate::BufStream; use bytes::Buf; use futures::{Async, Poll, Stream}; -use BufStream; /// Converts a `Stream` of `Buf` types into a `BufStream`. /// diff --git a/tokio-buf/tests/buf_stream.rs b/tokio-buf/tests/buf_stream.rs index 35a3f938..a31826f0 100644 --- a/tokio-buf/tests/buf_stream.rs +++ b/tokio-buf/tests/buf_stream.rs @@ -1,7 +1,5 @@ -extern crate tokio_buf; - use tokio_buf::BufStream; // Ensures that `BufStream` can be a trait object #[allow(dead_code)] -fn obj(_: &mut BufStream) {} +fn obj(_: &mut dyn BufStream) {} diff --git a/tokio-buf/tests/chain.rs b/tokio-buf/tests/chain.rs index 7cc7ea70..798dd96c 100644 --- a/tokio-buf/tests/chain.rs +++ b/tokio-buf/tests/chain.rs @@ -1,15 +1,9 @@ #![cfg(feature = "util")] -extern crate bytes; -extern crate futures; -extern crate tokio_buf; - use futures::Async::*; use tokio_buf::{BufStream, BufStreamExt}; -#[macro_use] mod support; - use support::*; #[test] diff --git a/tokio-buf/tests/collect.rs b/tokio-buf/tests/collect.rs index dd367c2d..f9bb401c 100644 --- a/tokio-buf/tests/collect.rs +++ b/tokio-buf/tests/collect.rs @@ -1,16 +1,10 @@ #![cfg(feature = "util")] -extern crate bytes; -extern crate futures; -extern crate tokio_buf; - use bytes::Bytes; use futures::Future; use tokio_buf::BufStreamExt; -#[macro_use] mod support; - use support::*; macro_rules! test_collect_impl { diff --git a/tokio-buf/tests/iter.rs b/tokio-buf/tests/iter.rs index 365a396e..464ff461 100644 --- a/tokio-buf/tests/iter.rs +++ b/tokio-buf/tests/iter.rs @@ -1,12 +1,7 @@ -extern crate bytes; -extern crate futures; -extern crate tokio_buf; - use futures::Async::*; use std::io::Cursor; use tokio_buf::{util, BufStream}; -#[macro_use] mod support; type Buf = Cursor<&'static [u8]>; diff --git a/tokio-buf/tests/limit.rs b/tokio-buf/tests/limit.rs index 1cd90921..d08a9083 100644 --- a/tokio-buf/tests/limit.rs +++ b/tokio-buf/tests/limit.rs @@ -1,16 +1,10 @@ #![cfg(feature = "util")] -extern crate bytes; -extern crate futures; -extern crate tokio_buf; - use futures::Async::*; use futures::Future; use tokio_buf::{BufStream, BufStreamExt}; -#[macro_use] mod support; - use support::*; #[test] diff --git a/tokio-buf/tests/size_hint.rs b/tokio-buf/tests/size_hint.rs index 45f86765..467a4a2d 100644 --- a/tokio-buf/tests/size_hint.rs +++ b/tokio-buf/tests/size_hint.rs @@ -1,5 +1,3 @@ -extern crate tokio_buf; - use tokio_buf::SizeHint; #[test] diff --git a/tokio-buf/tests/stream.rs b/tokio-buf/tests/stream.rs index 3491feb4..c7a394fc 100644 --- a/tokio-buf/tests/stream.rs +++ b/tokio-buf/tests/stream.rs @@ -1,15 +1,9 @@ -extern crate bytes; -extern crate futures; -extern crate tokio_buf; -extern crate tokio_mock_task; - use futures::sync::mpsc; use futures::Async::*; use std::io::Cursor; use tokio_buf::{util, BufStream}; use tokio_mock_task::MockTask; -#[macro_use] mod support; type Buf = Cursor<&'static [u8]>; diff --git a/tokio-buf/tests/string.rs b/tokio-buf/tests/string.rs index a99db209..754a4a7e 100644 --- a/tokio-buf/tests/string.rs +++ b/tokio-buf/tests/string.rs @@ -1,12 +1,7 @@ -extern crate bytes; -extern crate futures; -extern crate tokio_buf; - use futures::Async::*; use std::fmt; use tokio_buf::BufStream; -#[macro_use] mod support; fn test_hello_world(mut bs: B) diff --git a/tokio-buf/tests/support.rs b/tokio-buf/tests/support.rs index c8d7abfc..a5e0f0b7 100644 --- a/tokio-buf/tests/support.rs +++ b/tokio-buf/tests/support.rs @@ -1,9 +1,5 @@ #![allow(unused)] -extern crate bytes; -extern crate futures; -extern crate tokio_buf; - use bytes::Buf; use futures::Async::*; use futures::Poll; @@ -12,6 +8,7 @@ use tokio_buf::{BufStream, SizeHint}; use std::collections::VecDeque; use std::io::Cursor; +#[macro_export] macro_rules! assert_buf_eq { ($actual:expr, $expect:expr) => {{ use bytes::Buf; @@ -27,6 +24,7 @@ macro_rules! assert_buf_eq { }}; } +#[macro_export] macro_rules! assert_none { ($actual:expr) => { match $actual { @@ -36,6 +34,7 @@ macro_rules! assert_none { }; } +#[macro_export] macro_rules! assert_not_ready { ($actual:expr) => { match $actual { diff --git a/tokio-codec/Cargo.toml b/tokio-codec/Cargo.toml index b6dbbdf6..bbc29c33 100644 --- a/tokio-codec/Cargo.toml +++ b/tokio-codec/Cargo.toml @@ -7,8 +7,9 @@ name = "tokio-codec" # - Cargo.toml # - README.md # - Update CHANGELOG.md. -# - Create "v0.1.x" git tag. -version = "0.1.1" +# - Create "v0.2.x" git tag. +version = "0.2.0" +edition = "2018" authors = ["Carl Lerche ", "Bryan Burgers "] license = "MIT" repository = "https://github.com/tokio-rs/tokio" @@ -18,8 +19,9 @@ description = """ Utilities for encoding and decoding frames. """ categories = ["asynchronous"] +publish = false [dependencies] -tokio-io = "0.1.7" +tokio-io = { version = "0.2.0", path = "../tokio-io" } bytes = "0.4.7" futures = "0.1.18" diff --git a/tokio-codec/README.md b/tokio-codec/README.md index e0c1a385..4c0bf890 100644 --- a/tokio-codec/README.md +++ b/tokio-codec/README.md @@ -4,21 +4,6 @@ Utilities for encoding and decoding frames. [Documentation](https://docs.rs/tokio-codec) -## Usage - -First, add this to your `Cargo.toml`: - -```toml -[dependencies] -tokio-codec = "0.1" -``` - -Next, add this to your crate: - -```rust -extern crate tokio_codec; -``` - You can find extensive documentation and examples about how to use this crate online at [https://tokio.rs](https://tokio.rs). The [API documentation](https://docs.rs/tokio-codec) is also a great place to get started diff --git a/tokio-codec/src/lib.rs b/tokio-codec/src/lib.rs index a5ed45d0..1e22feb4 100644 --- a/tokio-codec/src/lib.rs +++ b/tokio-codec/src/lib.rs @@ -1,5 +1,7 @@ -#![deny(missing_docs, missing_debug_implementations, warnings)] #![doc(html_root_url = "https://docs.rs/tokio-codec/0.1.1")] +#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![cfg_attr(test, deny(warnings))] +#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! Utilities for encoding and decoding frames. //! @@ -13,13 +15,9 @@ //! [`Stream`]: # //! [transports]: # -extern crate bytes; -extern crate tokio_io; - mod bytes_codec; mod lines_codec; +pub use crate::bytes_codec::BytesCodec; +pub use crate::lines_codec::LinesCodec; pub use tokio_io::_tokio_codec::{Decoder, Encoder, Framed, FramedParts, FramedRead, FramedWrite}; - -pub use bytes_codec::BytesCodec; -pub use lines_codec::LinesCodec; diff --git a/tokio-codec/tests/codecs.rs b/tokio-codec/tests/codecs.rs index 0ab5256f..4256bbab 100644 --- a/tokio-codec/tests/codecs.rs +++ b/tokio-codec/tests/codecs.rs @@ -1,5 +1,4 @@ -extern crate bytes; -extern crate tokio_codec; +#![deny(warnings, rust_2018_idioms)] use bytes::{BufMut, Bytes, BytesMut}; use tokio_codec::{BytesCodec, Decoder, Encoder, LinesCodec}; diff --git a/tokio-codec/tests/framed.rs b/tokio-codec/tests/framed.rs index 53aafcbc..b17472ff 100644 --- a/tokio-codec/tests/framed.rs +++ b/tokio-codec/tests/framed.rs @@ -1,7 +1,4 @@ -extern crate bytes; -extern crate futures; -extern crate tokio_codec; -extern crate tokio_io; +#![deny(warnings, rust_2018_idioms)] use bytes::{Buf, BufMut, BytesMut, IntoBuf}; use futures::{Future, Stream}; diff --git a/tokio-codec/tests/framed_read.rs b/tokio-codec/tests/framed_read.rs index 53ec2038..ee7cc456 100644 --- a/tokio-codec/tests/framed_read.rs +++ b/tokio-codec/tests/framed_read.rs @@ -1,17 +1,12 @@ -extern crate bytes; -extern crate futures; -extern crate tokio_codec; -extern crate tokio_io; - -use tokio_codec::{Decoder, FramedRead}; -use tokio_io::AsyncRead; +#![deny(warnings, rust_2018_idioms)] use bytes::{Buf, BytesMut, IntoBuf}; use futures::Async::{NotReady, Ready}; use futures::Stream; - use std::collections::VecDeque; use std::io::{self, Read}; +use tokio_codec::{Decoder, FramedRead}; +use tokio_io::AsyncRead; macro_rules! mock { ($($x:expr,)*) => {{ diff --git a/tokio-codec/tests/framed_write.rs b/tokio-codec/tests/framed_write.rs index 9ce392c6..8f7a1c12 100644 --- a/tokio-codec/tests/framed_write.rs +++ b/tokio-codec/tests/framed_write.rs @@ -1,16 +1,11 @@ -extern crate bytes; -extern crate futures; -extern crate tokio_codec; -extern crate tokio_io; - -use tokio_codec::{Encoder, FramedWrite}; -use tokio_io::AsyncWrite; +#![deny(warnings, rust_2018_idioms)] use bytes::{BufMut, BytesMut}; use futures::{Poll, Sink}; - use std::collections::VecDeque; use std::io::{self, Write}; +use tokio_codec::{Encoder, FramedWrite}; +use tokio_io::AsyncWrite; macro_rules! mock { ($($x:expr,)*) => {{ diff --git a/tokio-current-thread/Cargo.toml b/tokio-current-thread/Cargo.toml index 386cad6d..af54d114 100644 --- a/tokio-current-thread/Cargo.toml +++ b/tokio-current-thread/Cargo.toml @@ -7,8 +7,9 @@ name = "tokio-current-thread" # - Cargo.toml # - README.md # - Update CHANGELOG.md. -# - Create "v0.1.x" git tag. -version = "0.1.6" +# - Create "v0.2.x" git tag. +version = "0.2.0" +edition = "2018" documentation = "https://docs.rs/tokio-current-thread/0.1.6/tokio_current_thread" repository = "https://github.com/tokio-rs/tokio" homepage = "https://github.com/tokio-rs/tokio" @@ -19,7 +20,8 @@ Single threaded executor which manage many tasks concurrently on the current thr """ keywords = ["futures", "tokio"] categories = ["concurrency", "asynchronous"] +publish = false [dependencies] -tokio-executor = "0.1.7" +tokio-executor = { version = "0.2.0", path = "../tokio-executor" } futures = "0.1.19" diff --git a/tokio-current-thread/src/lib.rs b/tokio-current-thread/src/lib.rs index 8dc3ebd1..a9800d8c 100644 --- a/tokio-current-thread/src/lib.rs +++ b/tokio-current-thread/src/lib.rs @@ -1,5 +1,7 @@ #![doc(html_root_url = "https://docs.rs/tokio-current-thread/0.1.6")] -#![deny(warnings, missing_docs, missing_debug_implementations)] +#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)] +#![cfg_attr(test, deny(warnings))] +#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] //! A single-threaded executor which executes tasks on the same thread from which //! they are spawned. @@ -25,19 +27,11 @@ //! [`block_on_all`]: fn.block_on_all.html //! [executor module]: https://docs.rs/tokio/0.1/tokio/executor/index.html -extern crate futures; -extern crate tokio_executor; - mod scheduler; -use self::scheduler::Scheduler; - -use tokio_executor::park::{Park, ParkThread, Unpark}; -use tokio_executor::{Enter, SpawnError}; - +use crate::scheduler::Scheduler; use futures::future::{ExecuteError, ExecuteErrorKind, Executor}; use futures::{executor, Async, Future}; - use std::cell::Cell; use std::error::Error; use std::fmt; @@ -45,6 +39,8 @@ use std::rc::Rc; use std::sync::{atomic, mpsc, Arc}; use std::thread; use std::time::{Duration, Instant}; +use tokio_executor::park::{Park, ParkThread, Unpark}; +use tokio_executor::{Enter, SpawnError}; /// Executes tasks on the current thread pub struct CurrentThread { @@ -64,7 +60,7 @@ pub struct CurrentThread { spawn_handle: Handle, /// Receiver for futures spawned from other threads - spawn_receiver: mpsc::Receiver + Send + 'static>>, + spawn_receiver: mpsc::Receiver + Send + 'static>>, /// The thread-local ID assigned to this executor. id: u64, @@ -97,7 +93,7 @@ impl Turn { } /// A `CurrentThread` instance bound to a supplied execution context. -pub struct Entered<'a, P: Park + 'a> { +pub struct Entered<'a, P: Park> { executor: &'a mut CurrentThread

, enter: &'a mut Enter, } @@ -109,7 +105,7 @@ pub struct RunError { } impl fmt::Display for RunError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{}", self.description()) } } @@ -127,7 +123,7 @@ pub struct RunTimeoutError { } impl fmt::Display for RunTimeoutError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{}", self.description()) } } @@ -149,7 +145,7 @@ pub struct TurnError { } impl fmt::Display for TurnError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{}", self.description()) } } @@ -167,7 +163,7 @@ pub struct BlockError { } impl fmt::Display for BlockError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "Block error") } } @@ -179,18 +175,22 @@ impl Error for BlockError { } /// This is mostly split out to make the borrow checker happy. -struct Borrow<'a, U: 'a> { +struct Borrow<'a, U> { id: u64, scheduler: &'a mut Scheduler, num_futures: &'a atomic::AtomicUsize, } trait SpawnLocal { - fn spawn_local(&mut self, future: Box>, already_counted: bool); + fn spawn_local( + &mut self, + future: Box>, + already_counted: bool, + ); } struct CurrentRunner { - spawn: Cell>, + spawn: Cell>, id: Cell>, } @@ -386,7 +386,7 @@ impl CurrentThread

{ &mut self.park } - fn borrow(&mut self) -> Borrow { + fn borrow(&mut self) -> Borrow<'_, P::Unpark> { Borrow { id: self.id, scheduler: &mut self.scheduler, @@ -424,7 +424,7 @@ impl Drop for CurrentThr