mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
io: expose std{in, out, err} under io feature (#1759)
This exposes `std{in, out, err}` under io feature by moving
`fs::blocking` module into `io::blocking`.
As `fs` feature depends on `io-trait` feature, `fs` implementations can
always access `io` module.
This commit is contained in:
@@ -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 = [
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<T> {
|
||||
}
|
||||
|
||||
impl<T> Blocking<T> {
|
||||
#[cfg(feature = "io")]
|
||||
pub(crate) fn new(inner: T) -> Blocking<T> {
|
||||
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;
|
||||
+17
-8
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::fs::blocking::Blocking;
|
||||
use crate::io::blocking::Blocking;
|
||||
use crate::io::AsyncWrite;
|
||||
|
||||
use std::io;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::fs::blocking::Blocking;
|
||||
use crate::io::blocking::Blocking;
|
||||
use crate::io::AsyncRead;
|
||||
|
||||
use std::io;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::fs::blocking::Blocking;
|
||||
use crate::io::blocking::Blocking;
|
||||
use crate::io::AsyncWrite;
|
||||
|
||||
use std::io;
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user