From ff41108834ab8fdf92e5c337b46637ba696d89c7 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Fri, 2 Aug 2019 15:23:44 -0400 Subject: [PATCH] io: move io helpers back into `tokio-io` (#1377) Utilities are made optional with a feature flag. --- tokio-io/Cargo.toml | 7 +++ .../src/io/async_buf_read_ext.rs | 21 +------- {tokio => tokio-io}/src/io/async_read_ext.rs | 33 +------------ {tokio => tokio-io}/src/io/async_write_ext.rs | 21 +------- {tokio => tokio-io}/src/io/copy.rs | 2 +- {tokio => tokio-io}/src/io/flush.rs | 3 +- {tokio => tokio-io}/src/io/lines.rs | 3 +- {tokio => tokio-io}/src/io/mod.rs | 9 ---- {tokio => tokio-io}/src/io/read.rs | 2 +- {tokio => tokio-io}/src/io/read_exact.rs | 2 +- {tokio => tokio-io}/src/io/read_line.rs | 2 +- {tokio => tokio-io}/src/io/read_to_end.rs | 3 +- {tokio => tokio-io}/src/io/read_to_string.rs | 2 +- {tokio => tokio-io}/src/io/read_until.rs | 2 +- {tokio => tokio-io}/src/io/write.rs | 2 +- {tokio => tokio-io}/src/io/write_all.rs | 3 +- tokio-io/src/lib.rs | 8 +++- .../io_copy.rs => tokio-io/tests/copy.rs | 2 +- .../io_lines.rs => tokio-io/tests/lines.rs | 2 +- .../io_read.rs => tokio-io/tests/read.rs | 2 +- .../tests/read_exact.rs | 2 +- .../tests/read_line.rs | 2 +- .../tests/read_to_end.rs | 2 +- .../tests/read_to_string.rs | 2 +- .../tests/read_until.rs | 2 +- .../io_write.rs => tokio-io/tests/write.rs | 2 +- .../tests/write_all.rs | 2 +- tokio/Cargo.toml | 5 +- tokio/src/io.rs | 48 +++++++++++++++++++ 29 files changed, 88 insertions(+), 110 deletions(-) rename {tokio => tokio-io}/src/io/async_buf_read_ext.rs (91%) rename {tokio => tokio-io}/src/io/async_read_ext.rs (82%) rename {tokio => tokio-io}/src/io/async_write_ext.rs (75%) rename {tokio => tokio-io}/src/io/copy.rs (98%) rename {tokio => tokio-io}/src/io/flush.rs (96%) rename {tokio => tokio-io}/src/io/lines.rs (97%) rename {tokio => tokio-io}/src/io/mod.rs (83%) rename {tokio => tokio-io}/src/io/read.rs (97%) rename {tokio => tokio-io}/src/io/read_exact.rs (98%) rename {tokio => tokio-io}/src/io/read_line.rs (98%) rename {tokio => tokio-io}/src/io/read_to_end.rs (99%) rename {tokio => tokio-io}/src/io/read_to_string.rs (98%) rename {tokio => tokio-io}/src/io/read_until.rs (98%) rename {tokio => tokio-io}/src/io/write.rs (97%) rename {tokio => tokio-io}/src/io/write_all.rs (97%) rename tokio/tests/io_copy.rs => tokio-io/tests/copy.rs (96%) rename tokio/tests/io_lines.rs => tokio-io/tests/lines.rs (95%) rename tokio/tests/io_read.rs => tokio-io/tests/read.rs (95%) rename tokio/tests/io_read_exact.rs => tokio-io/tests/read_exact.rs (95%) rename tokio/tests/io_read_line.rs => tokio-io/tests/read_line.rs (95%) rename tokio/tests/io_read_to_end.rs => tokio-io/tests/read_to_end.rs (95%) rename tokio/tests/io_read_to_string.rs => tokio-io/tests/read_to_string.rs (95%) rename tokio/tests/io_read_until.rs => tokio-io/tests/read_until.rs (95%) rename tokio/tests/io_write.rs => tokio-io/tests/write.rs (95%) rename tokio/tests/io_write_all.rs => tokio-io/tests/write_all.rs (96%) create mode 100644 tokio/src/io.rs diff --git a/tokio-io/Cargo.toml b/tokio-io/Cargo.toml index 2561ac217..8c55e5972 100644 --- a/tokio-io/Cargo.toml +++ b/tokio-io/Cargo.toml @@ -25,7 +25,14 @@ publish = false bytes = "0.4.7" log = "0.4" futures-core-preview = "0.3.0-alpha.17" +memchr = { version = "2.2", optional = true } [dev-dependencies] pin-utils = "0.1.0-alpha.4" +tokio = { version = "0.2.0", path = "../tokio" } +futures-util-preview = "0.3.0-alpha.17" tokio-test = { version = "0.2.0", path = "../tokio-test" } + +[features] +default = ["util"] +util = ["memchr"] \ No newline at end of file diff --git a/tokio/src/io/async_buf_read_ext.rs b/tokio-io/src/io/async_buf_read_ext.rs similarity index 91% rename from tokio/src/io/async_buf_read_ext.rs rename to tokio-io/src/io/async_buf_read_ext.rs index dfe0864a9..20a5bbf2a 100644 --- a/tokio/src/io/async_buf_read_ext.rs +++ b/tokio-io/src/io/async_buf_read_ext.rs @@ -1,8 +1,7 @@ use crate::io::lines::{lines, Lines}; use crate::io::read_line::{read_line, ReadLine}; use crate::io::read_until::{read_until, ReadUntil}; - -use tokio_io::AsyncBufRead; +use crate::AsyncBufRead; /// An extension trait which adds utility methods to `AsyncBufRead` types. pub trait AsyncBufReadExt: AsyncBufRead { @@ -19,12 +18,6 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// /// In the case of an error the buffer and the object will be discarded, with /// the error yielded. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn read_until<'a>(&'a mut self, byte: u8, buf: &'a mut Vec) -> ReadUntil<'a, Self> where Self: Unpin, @@ -55,12 +48,6 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// the event that all data read so far was valid UTF-8. /// /// [`read_until`]: AsyncBufReadExt::read_until - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> where Self: Unpin, @@ -83,12 +70,6 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// Each line of the stream has the same error semantics as [`AsyncBufReadExt::read_line`]. /// /// [`AsyncBufReadExt::read_line`]: AsyncBufReadExt::read_line - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn lines(self) -> Lines where Self: Sized, diff --git a/tokio/src/io/async_read_ext.rs b/tokio-io/src/io/async_read_ext.rs similarity index 82% rename from tokio/src/io/async_read_ext.rs rename to tokio-io/src/io/async_read_ext.rs index f04935c51..0976fd121 100644 --- a/tokio/src/io/async_read_ext.rs +++ b/tokio-io/src/io/async_read_ext.rs @@ -3,8 +3,7 @@ use crate::io::read::{read, Read}; use crate::io::read_exact::{read_exact, ReadExact}; use crate::io::read_to_end::{read_to_end, ReadToEnd}; use crate::io::read_to_string::{read_to_string, ReadToString}; - -use tokio_io::{AsyncRead, AsyncWrite}; +use crate::{AsyncRead, AsyncWrite}; /// An extension trait which adds utility methods to `AsyncRead` types. pub trait AsyncReadExt: AsyncRead { @@ -18,12 +17,6 @@ pub trait AsyncReadExt: AsyncRead { /// On success the number of bytes is returned and the `reader` and `writer` /// are consumed. On error the error is returned and the I/O objects are /// consumed as well. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn copy<'a, W>(&'a mut self, dst: &'a mut W) -> Copy<'a, Self, W> where Self: Unpin, @@ -36,12 +29,6 @@ pub trait AsyncReadExt: AsyncRead { /// /// The returned future will resolve to the number of bytes read once the /// read operation is completed. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn read<'a>(&'a mut self, dst: &'a mut [u8]) -> Read<'a, Self> where Self: Unpin, @@ -50,12 +37,6 @@ pub trait AsyncReadExt: AsyncRead { } /// Read exactly the amount of data needed to fill the provided buffer. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn read_exact<'a>(&'a mut self, dst: &'a mut [u8]) -> ReadExact<'a, Self> where Self: Unpin, @@ -66,12 +47,6 @@ pub trait AsyncReadExt: AsyncRead { /// Read all bytes until EOF in this source, placing them into `dst`. /// /// On success the total number of bytes read is returned. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn read_to_end<'a>(&'a mut self, dst: &'a mut Vec) -> ReadToEnd<'a, Self> where Self: Unpin, @@ -82,12 +57,6 @@ pub trait AsyncReadExt: AsyncRead { /// Read all bytes until EOF in this source, placing them into `dst`. /// /// On success the total number of bytes read is returned. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn read_to_string<'a>(&'a mut self, dst: &'a mut String) -> ReadToString<'a, Self> where Self: Unpin, diff --git a/tokio/src/io/async_write_ext.rs b/tokio-io/src/io/async_write_ext.rs similarity index 75% rename from tokio/src/io/async_write_ext.rs rename to tokio-io/src/io/async_write_ext.rs index 8b6a4844b..dc7b4a865 100644 --- a/tokio/src/io/async_write_ext.rs +++ b/tokio-io/src/io/async_write_ext.rs @@ -1,18 +1,11 @@ use crate::io::flush::{flush, Flush}; use crate::io::write::{write, Write}; use crate::io::write_all::{write_all, WriteAll}; - -use tokio_io::AsyncWrite; +use crate::AsyncWrite; /// An extension trait which adds utility methods to `AsyncWrite` types. pub trait AsyncWriteExt: AsyncWrite { /// Write a buffer into this writter, returning how many bytes were written. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ```` fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self> where Self: Unpin, @@ -21,12 +14,6 @@ pub trait AsyncWriteExt: AsyncWrite { } /// Attempt to write an entire buffer into this writter. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn write_all<'a>(&'a mut self, src: &'a [u8]) -> WriteAll<'a, Self> where Self: Unpin, @@ -35,12 +22,6 @@ pub trait AsyncWriteExt: AsyncWrite { } /// Flush the contents of this writer. - /// - /// # Examples - /// - /// ``` - /// unimplemented!(); - /// ``` fn flush(&mut self) -> Flush<'_, Self> where Self: Unpin, diff --git a/tokio/src/io/copy.rs b/tokio-io/src/io/copy.rs similarity index 98% rename from tokio/src/io/copy.rs rename to tokio-io/src/io/copy.rs index fe1ac052a..f363e308d 100644 --- a/tokio/src/io/copy.rs +++ b/tokio-io/src/io/copy.rs @@ -1,9 +1,9 @@ +use crate::{AsyncRead, AsyncWrite}; use futures_core::ready; use std::future::Future; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_io::{AsyncRead, AsyncWrite}; #[derive(Debug)] #[must_use = "futures do nothing unless you `.await` or poll them"] diff --git a/tokio/src/io/flush.rs b/tokio-io/src/io/flush.rs similarity index 96% rename from tokio/src/io/flush.rs rename to tokio-io/src/io/flush.rs index e9b9dde89..6fef526b9 100644 --- a/tokio/src/io/flush.rs +++ b/tokio-io/src/io/flush.rs @@ -1,10 +1,9 @@ +use crate::AsyncWrite; use std::future::Future; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_io::AsyncWrite; - /// A future used to fully flush an I/O object. /// /// Created by the [`AsyncWriteExt::flush`] function. diff --git a/tokio/src/io/lines.rs b/tokio-io/src/io/lines.rs similarity index 97% rename from tokio/src/io/lines.rs rename to tokio-io/src/io/lines.rs index 85e2abb1b..aa05736ed 100644 --- a/tokio/src/io/lines.rs +++ b/tokio-io/src/io/lines.rs @@ -1,6 +1,5 @@ use super::read_line::read_line_internal; - -use tokio_io::AsyncBufRead; +use crate::AsyncBufRead; use futures_core::{ready, Stream}; use std::io; diff --git a/tokio/src/io/mod.rs b/tokio-io/src/io/mod.rs similarity index 83% rename from tokio/src/io/mod.rs rename to tokio-io/src/io/mod.rs index cfa30e1e2..341177805 100644 --- a/tokio/src/io/mod.rs +++ b/tokio-io/src/io/mod.rs @@ -54,12 +54,3 @@ mod write_all; pub use self::async_buf_read_ext::AsyncBufReadExt; pub use self::async_read_ext::AsyncReadExt; pub use self::async_write_ext::AsyncWriteExt; - -// standard input, output, and error -#[cfg(feature = "fs")] -pub use tokio_fs::{stderr, stdin, stdout, Stderr, Stdin, Stdout}; -pub use tokio_io::{AsyncBufRead, AsyncRead, AsyncWrite}; - -// Re-export io::Error so that users don't have to deal -// with conflicts when `use`ing `tokio::io` and `std::io`. -pub use std::io::{Error, ErrorKind, Result}; diff --git a/tokio/src/io/read.rs b/tokio-io/src/io/read.rs similarity index 97% rename from tokio/src/io/read.rs rename to tokio-io/src/io/read.rs index acfcae430..449dac777 100644 --- a/tokio/src/io/read.rs +++ b/tokio-io/src/io/read.rs @@ -1,9 +1,9 @@ +use crate::AsyncRead; use std::future::Future; use std::io; use std::marker::Unpin; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_io::AsyncRead; /// Tries to read some bytes directly into the given `buf` in asynchronous /// manner, returning a future type. diff --git a/tokio/src/io/read_exact.rs b/tokio-io/src/io/read_exact.rs similarity index 98% rename from tokio/src/io/read_exact.rs rename to tokio-io/src/io/read_exact.rs index 7db5acfdf..63006ab27 100644 --- a/tokio/src/io/read_exact.rs +++ b/tokio-io/src/io/read_exact.rs @@ -1,10 +1,10 @@ +use crate::AsyncRead; use futures_core::ready; use std::future::Future; use std::io; use std::marker::Unpin; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_io::AsyncRead; /// A future which can be used to easily read exactly enough bytes to fill /// a buffer. diff --git a/tokio/src/io/read_line.rs b/tokio-io/src/io/read_line.rs similarity index 98% rename from tokio/src/io/read_line.rs rename to tokio-io/src/io/read_line.rs index 804d48f98..99a50be06 100644 --- a/tokio/src/io/read_line.rs +++ b/tokio-io/src/io/read_line.rs @@ -1,4 +1,5 @@ use super::read_until::read_until_internal; +use crate::AsyncBufRead; use futures_core::ready; use std::future::Future; use std::io; @@ -6,7 +7,6 @@ use std::mem; use std::pin::Pin; use std::str; use std::task::{Context, Poll}; -use tokio_io::AsyncBufRead; /// Future for the [`read_line`](crate::io::AsyncBufReadExt::read_line) method. #[derive(Debug)] diff --git a/tokio/src/io/read_to_end.rs b/tokio-io/src/io/read_to_end.rs similarity index 99% rename from tokio/src/io/read_to_end.rs rename to tokio-io/src/io/read_to_end.rs index 558be6b8d..2854ef8d4 100644 --- a/tokio/src/io/read_to_end.rs +++ b/tokio-io/src/io/read_to_end.rs @@ -1,5 +1,4 @@ -use tokio_io::AsyncRead; - +use crate::AsyncRead; use futures_core::ready; use std::future::Future; use std::io; diff --git a/tokio/src/io/read_to_string.rs b/tokio-io/src/io/read_to_string.rs similarity index 98% rename from tokio/src/io/read_to_string.rs rename to tokio-io/src/io/read_to_string.rs index b9037443e..61c895108 100644 --- a/tokio/src/io/read_to_string.rs +++ b/tokio-io/src/io/read_to_string.rs @@ -1,10 +1,10 @@ use super::read_to_end::read_to_end_internal; +use crate::AsyncRead; use futures_core::ready; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use std::{io, mem, str}; -use tokio_io::AsyncRead; /// Future for the [`read_to_string`](super::AsyncReadExt::read_to_string) method. #[derive(Debug)] diff --git a/tokio/src/io/read_until.rs b/tokio-io/src/io/read_until.rs similarity index 98% rename from tokio/src/io/read_until.rs rename to tokio-io/src/io/read_until.rs index ff28343c5..d3d501b1e 100644 --- a/tokio/src/io/read_until.rs +++ b/tokio-io/src/io/read_until.rs @@ -1,10 +1,10 @@ +use crate::AsyncBufRead; use futures_core::ready; use std::future::Future; use std::io; use std::mem; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_io::AsyncBufRead; /// Future for the [`read_until`](crate::io::AsyncBufReadExt::read_until) method. #[derive(Debug)] diff --git a/tokio/src/io/write.rs b/tokio-io/src/io/write.rs similarity index 97% rename from tokio/src/io/write.rs rename to tokio-io/src/io/write.rs index f31b1796a..89ee86a39 100644 --- a/tokio/src/io/write.rs +++ b/tokio-io/src/io/write.rs @@ -1,8 +1,8 @@ +use crate::AsyncWrite; use std::future::Future; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_io::AsyncWrite; /// A future to write some of the buffer to an `AsyncWrite`. #[derive(Debug)] diff --git a/tokio/src/io/write_all.rs b/tokio-io/src/io/write_all.rs similarity index 97% rename from tokio/src/io/write_all.rs rename to tokio-io/src/io/write_all.rs index 411dce4cc..ceb82e173 100644 --- a/tokio/src/io/write_all.rs +++ b/tokio-io/src/io/write_all.rs @@ -1,5 +1,4 @@ -use tokio_io::AsyncWrite; - +use crate::AsyncWrite; use futures_core::ready; use std::future::Future; use std::io; diff --git a/tokio-io/src/lib.rs b/tokio-io/src/lib.rs index d914f50c3..1c5fd005f 100644 --- a/tokio-io/src/lib.rs +++ b/tokio-io/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/tokio-io/0.1.12")] +#![doc(html_root_url = "https://docs.rs/tokio-io/0.2.0")] #![deny(missing_debug_implementations, missing_docs, rust_2018_idioms)] #![cfg_attr(test, deny(warnings))] #![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] @@ -15,9 +15,15 @@ mod async_buf_read; mod async_read; mod async_write; +#[cfg(feature = "util")] +mod io; + pub use self::async_buf_read::AsyncBufRead; pub use self::async_read::AsyncRead; pub use self::async_write::AsyncWrite; +#[cfg(feature = "util")] +pub use self::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt}; + // Re-export `Buf` and `BufMut` since they are part of the API pub use bytes::{Buf, BufMut}; diff --git a/tokio/tests/io_copy.rs b/tokio-io/tests/copy.rs similarity index 96% rename from tokio/tests/io_copy.rs rename to tokio-io/tests/copy.rs index 2fac7e85b..f9e3fee26 100644 --- a/tokio/tests/io_copy.rs +++ b/tokio-io/tests/copy.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite}; +use tokio_io::{AsyncRead, AsyncReadExt, AsyncWrite}; use tokio_test::assert_ok; use bytes::BytesMut; diff --git a/tokio/tests/io_lines.rs b/tokio-io/tests/lines.rs similarity index 95% rename from tokio/tests/io_lines.rs rename to tokio-io/tests/lines.rs index 02ce61494..63600db2e 100644 --- a/tokio/tests/io_lines.rs +++ b/tokio-io/tests/lines.rs @@ -2,7 +2,7 @@ #![feature(async_await)] use futures_util::StreamExt; -use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; +use tokio_io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; use tokio_test::assert_ok; use std::io; diff --git a/tokio/tests/io_read.rs b/tokio-io/tests/read.rs similarity index 95% rename from tokio/tests/io_read.rs rename to tokio-io/tests/read.rs index 0ec2bef35..b928bc784 100644 --- a/tokio/tests/io_read.rs +++ b/tokio-io/tests/read.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncRead, AsyncReadExt}; +use tokio_io::{AsyncRead, AsyncReadExt}; use tokio_test::assert_ok; use std::io; diff --git a/tokio/tests/io_read_exact.rs b/tokio-io/tests/read_exact.rs similarity index 95% rename from tokio/tests/io_read_exact.rs rename to tokio-io/tests/read_exact.rs index eae7435fd..617c929af 100644 --- a/tokio/tests/io_read_exact.rs +++ b/tokio-io/tests/read_exact.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncRead, AsyncReadExt}; +use tokio_io::{AsyncRead, AsyncReadExt}; use tokio_test::assert_ok; use std::io; diff --git a/tokio/tests/io_read_line.rs b/tokio-io/tests/read_line.rs similarity index 95% rename from tokio/tests/io_read_line.rs rename to tokio-io/tests/read_line.rs index 99b3b59e9..e8312c065 100644 --- a/tokio/tests/io_read_line.rs +++ b/tokio-io/tests/read_line.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; +use tokio_io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; use tokio_test::assert_ok; use std::io; diff --git a/tokio/tests/io_read_to_end.rs b/tokio-io/tests/read_to_end.rs similarity index 95% rename from tokio/tests/io_read_to_end.rs rename to tokio-io/tests/read_to_end.rs index ac0896250..c74860916 100644 --- a/tokio/tests/io_read_to_end.rs +++ b/tokio-io/tests/read_to_end.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncRead, AsyncReadExt}; +use tokio_io::{AsyncRead, AsyncReadExt}; use tokio_test::assert_ok; use std::pin::Pin; diff --git a/tokio/tests/io_read_to_string.rs b/tokio-io/tests/read_to_string.rs similarity index 95% rename from tokio/tests/io_read_to_string.rs rename to tokio-io/tests/read_to_string.rs index 4bbee177e..bf49bfb3f 100644 --- a/tokio/tests/io_read_to_string.rs +++ b/tokio-io/tests/read_to_string.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncRead, AsyncReadExt}; +use tokio_io::{AsyncRead, AsyncReadExt}; use tokio_test::assert_ok; use std::pin::Pin; diff --git a/tokio/tests/io_read_until.rs b/tokio-io/tests/read_until.rs similarity index 95% rename from tokio/tests/io_read_until.rs rename to tokio-io/tests/read_until.rs index 22945f55b..087e5e250 100644 --- a/tokio/tests/io_read_until.rs +++ b/tokio-io/tests/read_until.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; +use tokio_io::{AsyncBufRead, AsyncBufReadExt, AsyncRead}; use tokio_test::assert_ok; use std::io; diff --git a/tokio/tests/io_write.rs b/tokio-io/tests/write.rs similarity index 95% rename from tokio/tests/io_write.rs rename to tokio-io/tests/write.rs index 482f21bad..f4a582903 100644 --- a/tokio/tests/io_write.rs +++ b/tokio-io/tests/write.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncWrite, AsyncWriteExt}; +use tokio_io::{AsyncWrite, AsyncWriteExt}; use tokio_test::assert_ok; use bytes::BytesMut; diff --git a/tokio/tests/io_write_all.rs b/tokio-io/tests/write_all.rs similarity index 96% rename from tokio/tests/io_write_all.rs rename to tokio-io/tests/write_all.rs index b12e0f811..549027522 100644 --- a/tokio/tests/io_write_all.rs +++ b/tokio-io/tests/write_all.rs @@ -1,7 +1,7 @@ #![deny(warnings, rust_2018_idioms)] #![feature(async_await)] -use tokio::io::{AsyncWrite, AsyncWriteExt}; +use tokio_io::{AsyncWrite, AsyncWriteExt}; use tokio_test::assert_ok; use bytes::BytesMut; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index f340326e5..1370f221e 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -38,9 +38,9 @@ default = [ "uds", ] -codec = ["io", "tokio-codec"] +codec = ["io", "tokio-codec", "bytes"] fs = ["tokio-fs"] -io = ["bytes", "tokio-io", "memchr"] +io = ["tokio-io"] reactor = ["io", "tokio-reactor"] rt-full = [ "num_cpus", @@ -80,7 +80,6 @@ tokio-tcp = { version = "0.2.0", optional = true, path = "../tokio-tcp", feature tokio-udp = { version = "0.2.0", optional = true, path = "../tokio-udp" } tokio-timer = { version = "0.3.0", optional = true, path = "../tokio-timer", features = ["async-traits"] } tracing-core = { version = "0.1", optional = true } -memchr = { version = "2.2", optional = true } [target.'cfg(unix)'.dependencies] tokio-uds = { version = "0.3.0", optional = true, path = "../tokio-uds", features = ["async-traits"] } diff --git a/tokio/src/io.rs b/tokio/src/io.rs new file mode 100644 index 000000000..2dbec25ce --- /dev/null +++ b/tokio/src/io.rs @@ -0,0 +1,48 @@ +//! Asynchronous I/O. +//! +//! This module is the asynchronous version of `std::io`. Primarily, it +//! defines two traits, [`AsyncRead`] and [`AsyncWrite`], which extend the +//! `Read` and `Write` traits of the standard library. +//! +//! # AsyncRead and AsyncWrite +//! +//! [`AsyncRead`] and [`AsyncWrite`] must only be implemented for +//! non-blocking I/O types that integrate with the futures type system. In +//! other words, these types must never block the thread, and instead the +//! current task is notified when the I/O resource is ready. +//! +//! # Standard input and output +//! +//! Tokio provides asynchronous APIs to standard [input], [output], and [error]. +//! These APIs are very similar to the ones provided by `std`, but they also +//! implement [`AsyncRead`] and [`AsyncWrite`]. +//! +//! Unlike *most* other Tokio APIs, the standard input / output APIs +//! **must** be used from the context of the Tokio runtime as they require +//! Tokio specific features to function. +//! +//! [input]: fn.stdin.html +//! [output]: fn.stdout.html +//! [error]: fn.stderr.html +//! +//! # `std` re-exports +//! +//! Additionally, [`Error`], [`ErrorKind`], and [`Result`] are re-exported +//! from `std::io` for ease of use. +//! +//! [`AsyncRead`]: trait.AsyncRead.html +//! [`AsyncWrite`]: trait.AsyncWrite.html +//! [`Error`]: struct.Error.html +//! [`ErrorKind`]: enum.ErrorKind.html +//! [`Result`]: type.Result.html + +// standard input, output, and error +#[cfg(feature = "fs")] +pub use tokio_fs::{stderr, stdin, stdout, Stderr, Stdin, Stdout}; +pub use tokio_io::{ + AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, +}; + +// Re-export io::Error so that users don't have to deal +// with conflicts when `use`ing `tokio::io` and `std::io`. +pub use std::io::{Error, ErrorKind, Result};