fs: move into tokio (#1672)

A step towards collapsing Tokio sub crates into a single `tokio`
crate (#1318).

The `fs` implementation is now provided by the main `tokio` crate. The
`fs` functionality may still be excluded from the build by skipping the
`fs` feature flag.
This commit is contained in:
Carl Lerche
2019-10-21 15:49:00 -07:00
committed by GitHub
parent 6aa6ebb5bc
commit 978013a215
47 changed files with 162 additions and 521 deletions
-1
View File
@@ -4,7 +4,6 @@ members = [
"tokio",
"tokio-codec",
"tokio-executor",
"tokio-fs",
"tokio-io",
"tokio-macros",
"tokio-net",
-33
View File
@@ -120,39 +120,6 @@ project.
[guide]: CONTRIBUTING.md
## Project layout
The `tokio` crate, found at the root, is primarily intended for use by
application developers. Library authors should depend on the sub crates, which
have greater guarantees of stability.
The crates included as part of Tokio are:
* [`tokio-executor`]: Task executors and related utilities. Includes a
single-threaded executor and a multi-threaded, work-stealing, executor.
* [`tokio-fs`]: Filesystem (and standard in / out) APIs.
* [`tokio-codec`]: Utilities for encoding and decoding protocol frames.
* [`tokio-io`]: Asynchronous I/O related traits and utilities.
* [`tokio-macros`]: Macros for usage with Tokio.
* [`tokio-net`]: Event loop that drives I/O resources as well as TCP, UDP, and
unix domain socket apis.
* [ `tokio-timer`]: Time related APIs.
[`tokio-codec`]: tokio-codec
[`tokio-current-thread`]: tokio-current-thread
[`tokio-executor`]: tokio-executor
[`tokio-fs`]: tokio-fs
[`tokio-io`]: tokio-io
[`tokio-macros`]: tokio-macros
[`tokio-net`]: tokio-net
[`tokio-timer`]: tokio-timer
## Related Projects
In addition to the crates in this repository, the Tokio project also maintains
-1
View File
@@ -47,7 +47,6 @@ jobs:
cross: true
rust: beta
crates:
tokio-fs: []
tokio-net:
- process
- signal
-1
View File
@@ -4,7 +4,6 @@
tokio = { path = "tokio" }
tokio-codec = { path = "tokio-codec" }
tokio-executor = { path = "tokio-executor" }
tokio-fs = { path = "tokio-fs" }
tokio-io = { path = "tokio-io" }
tokio-macros = { path = "tokio-macros" }
tokio-net = { path = "tokio-net" }
-61
View File
@@ -1,61 +0,0 @@
# 0.2.0-alpha.6 (September 30, 2019)
- Move to `futures-*-preview 0.3.0-alpha.19`
- Move to `pin-project 0.4`
# 0.2.0-alpha.5 (September 19, 2019)
### Fix
- propagate flush for stdout / stderr. (#1528).
# 0.2.0-alpha.4 (August 29, 2019)
- Track tokio release.
# 0.2.0-alpha.3 (August 28, 2019)
### Changed
- Temporarily use a dedicated thread pool for all blocking operations (#1495).
# 0.2.0-alpha.2 (August 17, 2019)
### Changed
- Update `futures` dependency to 0.3.0-alpha.18.
# 0.2.0-alpha.1 (August 8, 2019)
### Changed
- Switch to `async`, `await`, and `std::future`.
# 0.1.6 (March 1, 2019)
### Added
- File::try_clone() (#850).
- Async equivalent of read / write file helpers being added to `std` (#896).
# 0.1.5 (January 6, 2019)
* Add examples to `File` API docs (#786).
# 0.1.4 (October 23, 2018)
* Provide `File::from_std` (#696).
# 0.1.3 (August 6, 2018)
* Add async equivalents to most of `std::fs` (#494).
# 0.1.2 (July 11, 2018)
* Add `metadata` and `File::metadata` ([#433](https://github.com/tokio-rs/tokio/pull/433), [#385](https://github.com/tokio-rs/tokio/pull/385))
* Add `File::seek` ([#434](https://github.com/tokio-rs/tokio/pull/434))
# 0.1.1 (June 13, 2018)
* Add `OpenOptions` ([#390](https://github.com/tokio-rs/tokio/pull/390))
* Add `into_std` to `File` ([#403](https://github.com/tokio-rs/tokio/pull/403))
* Use `tokio-codec` in examples
# 0.1.0 (May 2, 2018)
* Initial release
-41
View File
@@ -1,41 +0,0 @@
[package]
name = "tokio-fs"
# When releasing to crates.io:
# - Remove path dependencies
# - Update html_root_url.
# - Update doc url
# - Cargo.toml
# - Update CHANGELOG.md.
# - Create "v0.2.x" git tag.
version = "0.2.0-alpha.6"
edition = "2018"
authors = ["Tokio Contributors <[email protected]>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/tokio-rs/tokio"
homepage = "https://tokio.rs"
documentation = "https://docs.rs/tokio-fs/0.2.0-alpha.6/tokio_fs"
description = """
Filesystem API for Tokio.
"""
keywords = ["tokio", "futures", "fs", "file", "async"]
categories = ["asynchronous", "network-programming", "filesystem"]
[dependencies]
tokio-io = { version = "=0.2.0-alpha.6", features = ["util"], path = "../tokio-io" }
tokio-executor = { version = "=0.2.0-alpha.6", features = ["blocking"], path = "../tokio-executor" }
tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" }
futures-core-preview = "=0.3.0-alpha.19"
futures-util-preview = "=0.3.0-alpha.19"
lazy_static = "1.3.0"
[dev-dependencies]
tokio = { version = "=0.2.0-alpha.6", path = "../tokio" }
tokio-test = { version = "=0.2.0-alpha.6", path = "../tokio-test" }
rand = "0.7"
tempfile = "3"
[package.metadata.docs.rs]
all-features = true
-25
View File
@@ -1,25 +0,0 @@
Copyright (c) 2019 Tokio Contributors
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-13
View File
@@ -1,13 +0,0 @@
# Tokio FS
Asynchronous filesystem manipulation operations (and stdin, stdout, stderr).
## License
This project is licensed under the [MIT license](LICENSE).
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Tokio by you, shall be licensed as MIT, without any additional
terms or conditions.
-199
View File
@@ -1,199 +0,0 @@
#![warn(rust_2018_idioms)]
use tokio::fs::File;
use tokio::prelude::*;
use std::io::prelude::*;
use tempfile::NamedTempFile;
/*
use rand::{distributions, thread_rng, Rng};
use std::fs;
use std::io::SeekFrom;
use tempfile::Builder as TmpBuilder;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio_fs::*;
*/
const HELLO: &[u8] = b"hello world...";
#[tokio::test]
async fn basic_read() {
let mut tempfile = tempfile();
tempfile.write_all(HELLO).unwrap();
let mut file = File::open(tempfile.path()).await.unwrap();
let mut buf = [0; 1024];
let n = file.read(&mut buf).await.unwrap();
assert_eq!(n, HELLO.len());
assert_eq!(&buf[..n], HELLO);
}
#[tokio::test]
async fn basic_write() {
let tempfile = tempfile();
let mut file = File::create(tempfile.path()).await.unwrap();
file.write_all(HELLO).await.unwrap();
file.flush().await.unwrap();
let file = std::fs::read(tempfile.path()).unwrap();
assert_eq!(file, HELLO);
}
fn tempfile() -> NamedTempFile {
NamedTempFile::new().unwrap()
}
/*
mod pool;
#[test]
fn read_write() {
const NUM_CHARS: usize = 16 * 1_024;
let dir = TmpBuilder::new()
.prefix("tokio-fs-tests")
.tempdir()
.unwrap();
let file_path = dir.path().join("read_write.txt");
let contents: Vec<u8> = thread_rng()
.sample_iter(&distributions::Alphanumeric)
.take(NUM_CHARS)
.collect::<String>()
.into();
let file_path_2 = file_path.clone();
let contents_2 = contents.clone();
pool::run(async move {
let mut file = File::create(file_path).await?;
let metadata = file.metadata().await?;
assert!(metadata.is_file());
file.write(&contents).await?;
file.sync_all().await?;
Ok(())
});
let dst = fs::read(&file_path_2).unwrap();
assert_eq!(dst, contents_2);
pool::run(async move {
let buf = read(file_path_2).await?;
assert_eq!(buf, contents_2);
Ok(())
});
}
#[test]
fn read_write_helpers() {
const NUM_CHARS: usize = 16 * 1_024;
let dir = TmpBuilder::new()
.prefix("tokio-fs-tests")
.tempdir()
.unwrap();
let file_path = dir.path().join("read_write_all.txt");
let contents: Vec<u8> = thread_rng()
.sample_iter(&distributions::Alphanumeric)
.take(NUM_CHARS)
.collect::<String>()
.into();
let file_path_2 = file_path.clone();
let contents_2 = contents.clone();
pool::run(async move {
write(file_path, contents).await?;
Ok(())
});
let dst = fs::read(&file_path_2).unwrap();
assert_eq!(dst, contents_2);
pool::run(async move {
let buf = read(file_path_2).await?;
assert_eq!(buf, contents_2);
Ok(())
});
}
#[test]
fn metadata() {
let dir = TmpBuilder::new()
.prefix("tokio-fs-tests")
.tempdir()
.unwrap();
let file_path = dir.path().join("metadata.txt");
pool::run(async move {
assert!(tokio_fs::metadata(file_path.clone()).await.is_err());
File::create(file_path.clone()).await?;
let metadata = tokio_fs::metadata(file_path.clone()).await?;
assert!(metadata.is_file());
Ok(())
});
}
#[test]
fn seek() {
let dir = TmpBuilder::new()
.prefix("tokio-fs-tests")
.tempdir()
.unwrap();
let file_path = dir.path().join("seek.txt");
pool::run(async move {
let mut options = OpenOptions::new();
options.create(true).read(true).write(true);
let mut file = options.open(file_path).await.unwrap();
assert!(file.write(b"Hello, world!").await.is_ok());
file.seek(SeekFrom::End(-6)).await.unwrap();
let mut buf = vec![0; 5];
assert!(file.read(buf.as_mut()).await.is_ok());
assert_eq!(buf, b"world");
file.seek(SeekFrom::Start(0)).await.unwrap();
let mut buf = vec![0; 5];
assert!(file.read(buf.as_mut()).await.is_ok());
assert_eq!(buf, b"Hello");
Ok(())
});
}
#[test]
fn clone() {
use std::io::prelude::*;
let dir = TmpBuilder::new()
.prefix("tokio-fs-tests")
.tempdir()
.unwrap();
let file_path = dir.path().join("clone.txt");
let file_path_2 = file_path.clone();
pool::run(async move {
let mut file = File::create(file_path.clone()).await.unwrap();
let mut clone = file.try_clone().await.unwrap();
assert!(AsyncWriteExt::write(&mut file, b"clone ").await.is_ok());
assert!(AsyncWriteExt::write(&mut clone, b"successful")
.await
.is_ok());
Ok(())
});
let mut file = std::fs::File::open(&file_path_2).unwrap();
let mut dst = vec![];
file.read_to_end(&mut dst).unwrap();
assert_eq!(dst, b"clone successful")
}
*/
+2 -2
View File
@@ -37,7 +37,7 @@ default = [
]
codec = ["io", "tokio-codec", "bytes"]
fs = ["tokio-fs"]
fs = []
io = ["tokio-io"]
macros = ["tokio-macros"]
net = ["tcp", "udp", "uds"]
@@ -74,7 +74,6 @@ futures-util-preview = { version = "=0.3.0-alpha.19", features = ["sink"] }
bytes = { version = "0.4", optional = true }
num_cpus = { version = "1.8.0", optional = true }
tokio-codec = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-codec" }
tokio-fs = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-fs" }
tokio-io = { version = "=0.2.0-alpha.6", optional = true, features = ["util"], path = "../tokio-io" }
tokio-executor = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-executor" }
tokio-macros = { version = "=0.2.0-alpha.6", optional = true, path = "../tokio-macros" }
@@ -101,6 +100,7 @@ libc = "0.2"
num_cpus = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tempfile = "3.1.0"
time = "0.1"
[package.metadata.docs.rs]
-33
View File
@@ -119,39 +119,6 @@ project.
[guide]: CONTRIBUTING.md
## Project layout
The `tokio` crate, found at the root, is primarily intended for use by
application developers. Library authors should depend on the sub crates, which
have greater guarantees of stability.
The crates included as part of Tokio are:
* [`tokio-executor`]: Task executors and related utilities. Includes a
single-threaded executor and a multi-threaded, work-stealing, executor.
* [`tokio-fs`]: Filesystem (and standard in / out) APIs.
* [`tokio-codec`]: Utilities for encoding and decoding protocol frames.
* [`tokio-io`]: Asynchronous I/O related traits and utilities.
* [`tokio-macros`]: Macros for usage with Tokio.
* [`tokio-net`]: Event loop that drives I/O resources as well as TCP, UDP, and
unix domain socket apis.
* [ `tokio-timer`]: Time related APIs.
[`tokio-codec`]: tokio-codec
[`tokio-current-thread`]: tokio-current-thread
[`tokio-executor`]: tokio-executor
[`tokio-fs`]: tokio-fs
[`tokio-io`]: tokio-io
[`tokio-macros`]: tokio-macros
[`tokio-net`]: tokio-net
[`tokio-timer`]: tokio-timer
## Related Projects
In addition to the crates in this repository, the Tokio project also maintains
-14
View File
@@ -1,14 +0,0 @@
//! Asynchronous filesystem manipulation operations.
//!
//! This module contains basic methods and types for manipulating the contents
//! of the local filesystem from within the context of the Tokio runtime.
//!
//! Unlike *most* other Tokio APIs, the filesystem APIs **must** be used from
//! the context of the Tokio runtime as they require Tokio specific features to
//! function.
pub use tokio_fs::{
create_dir, create_dir_all, hard_link, metadata, os, read, read_dir, read_link, read_to_string,
remove_dir, remove_dir_all, remove_file, rename, set_permissions, symlink_metadata, write,
File, OpenOptions,
};
@@ -1,4 +1,4 @@
use crate::sys;
use crate::fs::sys;
use tokio_io::{AsyncRead, AsyncWrite};
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -3,8 +3,8 @@
//! [`File`]: file/struct.File.html
use self::State::*;
use crate::blocking::Buf;
use crate::{asyncify, sys};
use crate::fs::blocking::Buf;
use crate::fs::{asyncify, sys};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::fs::Metadata;
use std::io;
+54 -56
View File
@@ -1,16 +1,3 @@
#![doc(html_root_url = "https://docs.rs/tokio-fs/0.2.0-alpha.6")]
#![warn(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#![deny(intra_doc_link_resolution_failure)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
//! Asynchronous file and standard stream adaptation.
//!
//! This module contains utility methods and adapter types for input/output to
@@ -38,53 +25,64 @@
//! [`AsyncRead`]: https://docs.rs/tokio-io/0.1/tokio_io/trait.AsyncRead.html
//! [tokio-executor]: https://docs.rs/tokio-executor/0.2.0-alpha.2/tokio_executor/threadpool/index.html
mod blocking;
mod create_dir;
mod create_dir_all;
mod file;
mod hard_link;
mod metadata;
mod open_options;
pub mod os;
mod read;
mod read_dir;
mod read_link;
mod read_to_string;
mod remove_dir;
mod remove_dir_all;
mod remove_file;
mod rename;
mod set_permissions;
mod stderr;
mod stdin;
mod stdout;
mod symlink_metadata;
mod write;
pub(crate) mod blocking;
pub use crate::create_dir::create_dir;
pub use crate::create_dir_all::create_dir_all;
pub use crate::file::File;
pub use crate::hard_link::hard_link;
pub use crate::metadata::metadata;
pub use crate::open_options::OpenOptions;
pub use crate::read::read;
pub use crate::read_dir::{read_dir, DirEntry, ReadDir};
pub use crate::read_link::read_link;
pub use crate::read_to_string::read_to_string;
pub use crate::remove_dir::remove_dir;
pub use crate::remove_dir_all::remove_dir_all;
pub use crate::remove_file::remove_file;
pub use crate::rename::rename;
pub use crate::set_permissions::set_permissions;
pub use crate::stderr::{stderr, Stderr};
pub use crate::stdin::{stdin, Stdin};
pub use crate::stdout::{stdout, Stdout};
pub use crate::symlink_metadata::symlink_metadata;
pub use crate::write::write;
mod create_dir;
pub use self::create_dir::create_dir;
mod create_dir_all;
pub use self::create_dir_all::create_dir_all;
mod file;
pub use self::file::File;
mod hard_link;
pub use self::hard_link::hard_link;
mod metadata;
pub use self::metadata::metadata;
mod open_options;
pub use self::open_options::OpenOptions;
pub mod os;
mod read;
pub use self::read::read;
mod read_dir;
pub use self::read_dir::{read_dir, DirEntry, ReadDir};
mod read_link;
pub use self::read_link::read_link;
mod read_to_string;
pub use self::read_to_string::read_to_string;
mod remove_dir;
pub use self::remove_dir::remove_dir;
mod remove_dir_all;
pub use self::remove_dir_all::remove_dir_all;
mod remove_file;
pub use self::remove_file::remove_file;
mod rename;
pub use self::rename::rename;
mod set_permissions;
pub use self::set_permissions::set_permissions;
mod symlink_metadata;
pub use self::symlink_metadata::symlink_metadata;
mod write;
pub use self::write::write;
use std::io;
async fn asyncify<F, T>(f: F) -> io::Result<T>
pub(crate) async fn asyncify<F, T>(f: F) -> io::Result<T>
where
F: FnOnce() -> io::Result<T> + Send + 'static,
T: Send + 'static,
@@ -1,4 +1,4 @@
use crate::{asyncify, File};
use crate::fs::{asyncify, File};
use std::io;
use std::path::Path;
@@ -1,5 +1,4 @@
//! Unix-specific extensions to primitives in the `tokio_fs` module.
mod symlink;
pub use self::symlink::symlink;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,7 +1,7 @@
//! Windows-specific extensions for the primitives in the `tokio_fs` module.
mod symlink_dir;
mod symlink_file;
pub use self::symlink_dir::symlink_dir;
mod symlink_file;
pub use self::symlink_file::symlink_file;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::{io, path::Path};
@@ -1,4 +1,4 @@
use crate::{asyncify, sys};
use crate::fs::{asyncify, sys};
use futures_core::ready;
use futures_core::stream::Stream;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::{Path, PathBuf};
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::{io, path::Path};
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::io;
use std::path::Path;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::fs::Permissions;
use std::io;
@@ -1,4 +1,4 @@
use super::asyncify;
use crate::fs::asyncify;
use std::fs::Metadata;
use std::io;
@@ -1,4 +1,4 @@
use crate::asyncify;
use crate::fs::asyncify;
use std::{io, path::Path};
+16 -2
View File
@@ -36,9 +36,23 @@
//! [`ErrorKind`]: enum.ErrorKind.html
//! [`Result`]: type.Result.html
// standard input, output, and error
// TODO: These should not be guarded by `fs`
#[cfg(feature = "fs")]
pub use tokio_fs::{stderr, stdin, stdout, Stderr, Stdin, Stdout};
mod stderr;
#[cfg(feature = "fs")]
pub use self::stderr::{stderr, Stderr};
#[cfg(feature = "fs")]
mod stdin;
#[cfg(feature = "fs")]
pub use self::stdin::{stdin, Stdin};
#[cfg(feature = "fs")]
mod stdout;
#[cfg(feature = "fs")]
pub use self::stdout::{stdout, Stdout};
pub use tokio_io::split::split;
pub use tokio_io::{
empty, repeat, sink, AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, AsyncWrite,
@@ -1,4 +1,4 @@
use crate::blocking::Blocking;
use crate::fs::blocking::Blocking;
use tokio_io::AsyncWrite;
@@ -1,4 +1,4 @@
use crate::blocking::Blocking;
use crate::fs::blocking::Blocking;
use tokio_io::AsyncRead;
@@ -1,4 +1,4 @@
use crate::blocking::Blocking;
use crate::fs::blocking::Blocking;
use tokio_io::AsyncWrite;
+40
View File
@@ -0,0 +1,40 @@
#![warn(rust_2018_idioms)]
use tokio::fs::File;
use tokio::prelude::*;
use std::io::prelude::*;
use tempfile::NamedTempFile;
const HELLO: &[u8] = b"hello world...";
#[tokio::test]
async fn basic_read() {
let mut tempfile = tempfile();
tempfile.write_all(HELLO).unwrap();
let mut file = File::open(tempfile.path()).await.unwrap();
let mut buf = [0; 1024];
let n = file.read(&mut buf).await.unwrap();
assert_eq!(n, HELLO.len());
assert_eq!(&buf[..n], HELLO);
}
#[tokio::test]
async fn basic_write() {
let tempfile = tempfile();
let mut file = File::create(tempfile.path()).await.unwrap();
file.write_all(HELLO).await.unwrap();
file.flush().await.unwrap();
let file = std::fs::read(tempfile.path()).unwrap();
assert_eq!(file, HELLO);
}
fn tempfile() -> NamedTempFile {
NamedTempFile::new().unwrap()
}
@@ -1,23 +1,35 @@
#![warn(rust_2018_idioms)]
mod sys {
mod file;
pub(crate) mod pool;
pub(crate) use self::file::File;
pub(crate) use self::pool::{run, Blocking};
}
use sys::pool::{self, asyncify};
// Load source
#[allow(warnings)]
#[path = "../src/file.rs"]
#[path = "../src/fs/file.rs"]
mod file;
use file::File;
#[allow(warnings)]
#[path = "../src/blocking.rs"]
#[path = "../src/fs/blocking.rs"]
mod blocking;
// Load mocked types
mod support {
pub(crate) mod mock_file;
pub(crate) mod mock_pool;
}
pub(crate) use support::mock_pool as pool;
// Place them where the source expects them
pub(crate) mod fs {
pub(crate) use crate::blocking;
pub(crate) mod sys {
pub(crate) use crate::support::mock_file::File;
pub(crate) use crate::support::mock_pool::{run, Blocking};
}
pub(crate) use crate::support::mock_pool::asyncify;
}
use fs::sys;
use tokio::prelude::*;
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task};