diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 968c21572..1c2b24f16 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -28,6 +28,7 @@ default = [ "blocking", "fs", "io-util", + "io", "net", "process", "rt-full", @@ -42,6 +43,7 @@ dns = ["blocking"] fs = ["blocking"] io-driver = ["mio", "lazy_static", "sync"] # TODO: get rid of sync io-util = ["memchr"] +io = ["io-util", "blocking"] macros = ["tokio-macros"] net = ["dns", "tcp", "udp", "uds"] process = [ diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index 0ff45025b..af7be5863 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -3,8 +3,8 @@ //! [`File`]: file/struct.File.html use self::State::*; -use crate::fs::blocking::Buf; use crate::fs::{asyncify, sys}; +use crate::io::blocking::Buf; use crate::io::{AsyncRead, AsyncWrite}; use std::fmt; diff --git a/tokio/src/fs/mod.rs b/tokio/src/fs/mod.rs index 9108116ab..937242803 100644 --- a/tokio/src/fs/mod.rs +++ b/tokio/src/fs/mod.rs @@ -22,8 +22,6 @@ //! //! [`AsyncRead`]: https://docs.rs/tokio-io/0.1/tokio_io/trait.AsyncRead.html -pub(crate) mod blocking; - mod create_dir; pub use self::create_dir::create_dir; diff --git a/tokio/src/fs/blocking.rs b/tokio/src/io/blocking.rs similarity index 98% rename from tokio/src/fs/blocking.rs rename to tokio/src/io/blocking.rs index 64398cbbd..79e2e0b73 100644 --- a/tokio/src/fs/blocking.rs +++ b/tokio/src/io/blocking.rs @@ -1,4 +1,4 @@ -use crate::fs::sys; +use crate::io::sys; use crate::io::{AsyncRead, AsyncWrite}; use std::cmp; @@ -35,6 +35,7 @@ enum State { } impl Blocking { + #[cfg(feature = "io")] pub(crate) fn new(inner: T) -> Blocking { Blocking { inner: Some(inner), @@ -264,6 +265,7 @@ impl Buf { res } + #[cfg(feature = "fs")] pub(crate) fn discard_read(&mut self) -> i64 { let ret = -(self.bytes().len() as i64); self.pos = 0; diff --git a/tokio/src/io/mod.rs b/tokio/src/io/mod.rs index 3f95c330c..df84efd7d 100644 --- a/tokio/src/io/mod.rs +++ b/tokio/src/io/mod.rs @@ -36,6 +36,9 @@ //! [`ErrorKind`]: enum.ErrorKind.html //! [`Result`]: type.Result.html +#[cfg(any(feature = "io", feature = "fs"))] +pub(crate) mod blocking; + mod async_buf_read; pub use self::async_buf_read::AsyncBufRead; @@ -58,24 +61,30 @@ pub use self::util::{ BufWriter, Copy, Empty, Lines, Repeat, Sink, Split, Take, }; -// TODO: These should not be guarded by `fs` - -#[cfg(feature = "fs")] +#[cfg(feature = "io")] mod stderr; -#[cfg(feature = "fs")] +#[cfg(feature = "io")] pub use self::stderr::{stderr, Stderr}; -#[cfg(feature = "fs")] +#[cfg(feature = "io")] mod stdin; -#[cfg(feature = "fs")] +#[cfg(feature = "io")] pub use self::stdin::{stdin, Stdin}; -#[cfg(feature = "fs")] +#[cfg(feature = "io")] mod stdout; -#[cfg(feature = "fs")] +#[cfg(feature = "io")] pub use self::stdout::{stdout, Stdout}; // Re-export io::Error so that users don't have to deal // with conflicts when `use`ing `tokio::io` and `std::io`. #[cfg(feature = "io-util")] pub use std::io::{Error, ErrorKind, Result}; + +/// Types in this module can be mocked out in tests. +#[cfg(any(feature = "io", feature = "fs"))] +mod sys { + // TODO: don't rename + pub(crate) use crate::blocking::spawn_blocking as run; + pub(crate) use crate::task::JoinHandle as Blocking; +} diff --git a/tokio/src/io/stderr.rs b/tokio/src/io/stderr.rs index 2b9c4d715..9e3f2e9b6 100644 --- a/tokio/src/io/stderr.rs +++ b/tokio/src/io/stderr.rs @@ -1,4 +1,4 @@ -use crate::fs::blocking::Blocking; +use crate::io::blocking::Blocking; use crate::io::AsyncWrite; use std::io; diff --git a/tokio/src/io/stdin.rs b/tokio/src/io/stdin.rs index f85bbddc0..58b190826 100644 --- a/tokio/src/io/stdin.rs +++ b/tokio/src/io/stdin.rs @@ -1,4 +1,4 @@ -use crate::fs::blocking::Blocking; +use crate::io::blocking::Blocking; use crate::io::AsyncRead; use std::io; diff --git a/tokio/src/io/stdout.rs b/tokio/src/io/stdout.rs index ea96dd33e..c06c7d386 100644 --- a/tokio/src/io/stdout.rs +++ b/tokio/src/io/stdout.rs @@ -1,4 +1,4 @@ -use crate::fs::blocking::Blocking; +use crate::io::blocking::Blocking; use crate::io::AsyncWrite; use std::io; diff --git a/tokio/tests/fs_file_mocked.rs b/tokio/tests/fs_file_mocked.rs index d2eaadde9..2b05d8c45 100644 --- a/tokio/tests/fs_file_mocked.rs +++ b/tokio/tests/fs_file_mocked.rs @@ -18,7 +18,7 @@ mod file; use file::File; #[allow(warnings)] -#[path = "../src/fs/blocking.rs"] +#[path = "../src/io/blocking.rs"] mod blocking; // Load mocked types @@ -29,9 +29,16 @@ mod support { pub(crate) use support::mock_pool as pool; // Place them where the source expects them -pub(crate) mod fs { +pub(crate) mod io { + pub(crate) use tokio::io::*; + pub(crate) use crate::blocking; + pub(crate) mod sys { + pub(crate) use crate::support::mock_pool::{run, Blocking}; + } +} +pub(crate) mod fs { pub(crate) mod sys { pub(crate) use crate::support::mock_file::File; pub(crate) use crate::support::mock_pool::{run, Blocking}; @@ -41,7 +48,6 @@ pub(crate) mod fs { } use fs::sys; -use tokio::io; use tokio::prelude::*; use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task};