summaryrefslogtreecommitdiffstats
path: root/tokio-fs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio-fs')
-rw-r--r--tokio-fs/Cargo.toml15
-rw-r--r--tokio-fs/examples/std-echo.rs7
-rw-r--r--tokio-fs/src/create_dir.rs5
-rw-r--r--tokio-fs/src/create_dir_all.rs5
-rw-r--r--tokio-fs/src/file/clone.rs2
-rw-r--r--tokio-fs/src/file/create.rs6
-rw-r--r--tokio-fs/src/file/metadata.rs6
-rw-r--r--tokio-fs/src/file/mod.rs352
-rw-r--r--tokio-fs/src/file/open.rs6
-rw-r--r--tokio-fs/src/file/open_options.rs1
-rw-r--r--tokio-fs/src/file/seek.rs4
-rw-r--r--tokio-fs/src/hard_link.rs5
-rw-r--r--tokio-fs/src/lib.rs46
-rw-r--r--tokio-fs/src/metadata.rs2
-rw-r--r--tokio-fs/src/os/unix.rs5
-rw-r--r--tokio-fs/src/os/windows/symlink_dir.rs5
-rw-r--r--tokio-fs/src/os/windows/symlink_file.rs5
-rw-r--r--tokio-fs/src/read.rs25
-rw-r--r--tokio-fs/src/read_dir.rs91
-rw-r--r--tokio-fs/src/read_link.rs5
-rw-r--r--tokio-fs/src/remove_dir.rs5
-rw-r--r--tokio-fs/src/remove_file.rs5
-rw-r--r--tokio-fs/src/rename.rs5
-rw-r--r--tokio-fs/src/set_permissions.rs5
-rw-r--r--tokio-fs/src/stderr.rs8
-rw-r--r--tokio-fs/src/stdin.rs5
-rw-r--r--tokio-fs/src/stdout.rs8
-rw-r--r--tokio-fs/src/symlink_metadata.rs2
-rw-r--r--tokio-fs/src/write.rs29
-rw-r--r--tokio-fs/tests/dir.rs4
-rw-r--r--tokio-fs/tests/file.rs14
-rw-r--r--tokio-fs/tests/link.rs7
-rw-r--r--tokio-fs/tests/pool/mod.rs4
33 files changed, 293 insertions, 406 deletions
diff --git a/tokio-fs/Cargo.toml b/tokio-fs/Cargo.toml
index 46613dd6..59d2ae57 100644
--- a/tokio-fs/Cargo.toml
+++ b/tokio-fs/Cargo.toml
@@ -7,8 +7,9 @@ name = "tokio-fs"
# - 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"
authors = ["Carl Lerche <me@carllerche.com>"]
license = "MIT"
readme = "README.md"
@@ -20,16 +21,16 @@ Filesystem API for Tokio.
"""
keywords = ["tokio", "futures", "fs", "file", "async"]
categories = ["asynchronous", "network-programming", "filesystem"]
+publish = false
[dependencies]
futures = "0.1.21"
-tokio-threadpool = "0.1.3"
-tokio-io = "0.1.6"
+tokio-threadpool = { version = "0.2.0", path = "../tokio-threadpool" }
+tokio-io = { version = "0.2.0", path = "../tokio-io" }
[dev-dependencies]
rand = "0.6"
tempfile = "3"
tempdir = "0.3"
-tokio-io = "0.1.6"
-tokio-codec = "0.1.0"
-tokio = "0.1.7"
+tokio-codec = { version = "0.2.0", path = "../tokio-codec" }
+tokio = { version = "0.2.0", path = "../tokio" }
diff --git a/tokio-fs/examples/std-echo.rs b/tokio-fs/examples/std-echo.rs
index f7433fba..58028bb3 100644
--- a/tokio-fs/examples/std-echo.rs
+++ b/tokio-fs/examples/std-echo.rs
@@ -1,11 +1,6 @@
//! Echo everything received on STDIN to STDOUT.
#![deny(deprecated, warnings)]
-extern crate futures;
-extern crate tokio_codec;
-extern crate tokio_fs;
-extern crate tokio_threadpool;
-
use tokio_codec::{FramedRead, FramedWrite, LinesCodec};
use tokio_fs::{stderr, stdin, stdout};
use tokio_threadpool::Builder;
@@ -14,7 +9,7 @@ use futures::{Future, Sink, Stream};
use std::io;
-pub fn main() -> Result<(), Box<std::error::Error>> {
+pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let pool = Builder::new().pool_size(1).build();
pool.spawn({
diff --git a/tokio-fs/src/create_dir.rs b/tokio-fs/src/create_dir.rs
index 7ae71d7f..a07c1ad5 100644
--- a/tokio-fs/src/create_dir.rs
+++ b/tokio-fs/src/create_dir.rs
@@ -1,9 +1,8 @@
+use futures::{Future, Poll};
use std::fs;
use std::io;
use std::path::Path;
-use futures::{Future, Poll};
-
/// Creates a new, empty directory at the provided path
///
/// This is an async version of [`std::fs::create_dir`][std]
@@ -39,6 +38,6 @@ where
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- ::blocking_io(|| fs::create_dir(&self.path))
+ crate::blocking_io(|| fs::create_dir(&self.path))
}
}
diff --git a/tokio-fs/src/create_dir_all.rs b/tokio-fs/src/create_dir_all.rs
index 67b0aaf1..9f034fa4 100644
--- a/tokio-fs/src/create_dir_all.rs
+++ b/tokio-fs/src/create_dir_all.rs
@@ -1,9 +1,8 @@
+use futures::{Future, Poll};
use std::fs;
use std::io;
use std::path::Path;
-use futures::{Future, Poll};
-
/// Recursively create a directory and all of its parent components if they
/// are missing.
///
@@ -40,6 +39,6 @@ where
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- ::blocking_io(|| fs::create_dir_all(&self.path))
+ crate::blocking_io(|| fs::create_dir_all(&self.path))
}
}
diff --git a/tokio-fs/src/file/clone.rs b/tokio-fs/src/file/clone.rs
index 9aaaf087..1bbb6cc9 100644
--- a/tokio-fs/src/file/clone.rs
+++ b/tokio-fs/src/file/clone.rs
@@ -1,7 +1,5 @@
use super::File;
-
use futures::{Future, Poll};
-
use std::io;
/// Future returned by `File::try_clone`.
diff --git a/tokio-fs/src/file/create.rs b/tokio-fs/src/file/create.rs
index e92575cc..da03779e 100644
--- a/tokio-fs/src/file/create.rs
+++ b/tokio-fs/src/file/create.rs
@@ -1,7 +1,5 @@
use super::File;
-
-use futures::{Future, Poll};
-
+use futures::{try_ready, Future, Poll};
use std::fs::File as StdFile;
use std::io;
use std::path::Path;
@@ -29,7 +27,7 @@ where
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- let std = try_ready!(::blocking_io(|| StdFile::create(&self.path)));
+ let std = try_ready!(crate::blocking_io(|| StdFile::create(&self.path)));
let file = File::from_std(std);
Ok(file.into())
diff --git a/tokio-fs/src/file/metadata.rs b/tokio-fs/src/file/metadata.rs
index e6eaf6c8..7a3c5ef9 100644
--- a/tokio-fs/src/file/metadata.rs
+++ b/tokio-fs/src/file/metadata.rs
@@ -1,7 +1,5 @@
use super::File;
-
-use futures::{Future, Poll};
-
+use futures::{try_ready, Future, Poll};
use std::fs::File as StdFile;
use std::fs::Metadata;
use std::io;
@@ -29,7 +27,7 @@ impl Future for MetadataFuture {
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- let metadata = try_ready!(::blocking_io(|| StdFile::metadata(self.std())));
+ let metadata = try_ready!(crate::blocking_io(|| StdFile::metadata(self.std())));
let file = self.file.take().expect(POLL_AFTER_RESOLVE);
Ok((file, metadata).into())
diff --git a/tokio-fs/src/file/mod.rs b/tokio-fs/src/file/mod.rs
index 13601b39..c51bf5b5 100644
--- a/tokio-fs/src/file/mod.rs
+++ b/tokio-fs/src/file/mod.rs
@@ -16,13 +16,11 @@ pub use self::open::OpenFuture;
pub use self::open_options::OpenOptions;
pub use self::seek::SeekFuture;
-use tokio_io::{AsyncRead, AsyncWrite};
-
use futures::Poll;
-
use std::fs::{File as StdFile, Metadata, Permissions};
use std::io::{self, Read, Seek, Write};
use std::path::Path;
+use tokio_io::{AsyncRead, AsyncWrite};
/// A reference to an open file on the filesystem.
///
@@ -42,39 +40,32 @@ use std::path::Path;
/// Create a new file and asynchronously write bytes to it:
///
/// ```no_run
-/// extern crate tokio;
-///
/// use tokio::prelude::{AsyncWrite, Future};
///
-/// fn main() {
-/// let task = tokio::fs::File::create("foo.txt")
-/// .and_then(|mut file| file.poll_write(b"hello, world!"))
-/// .map(|res| {
-/// println!("{:?}", res);
-/// }).map_err(|err| eprintln!("IO error: {:?}", err));
+/// let task = tokio::fs::File::create("foo.txt")
+/// .and_then(|mut file| file.poll_write(b"hello, world!"))
+/// .map(|res| {
+/// println!("{:?}", res);
+/// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
-/// tokio::run(task);
-/// }
+/// tokio::run(task);
/// ```
///
/// Read the contents of a file into a buffer
///
/// ```no_run
-/// extern crate tokio;
-///
/// use tokio::prelude::{AsyncRead, Future};
///
-/// fn main() {
-/// let task = tokio::fs::File::open("foo.txt")
-/// .and_then(|mut file| {
-/// let mut contents = vec![];
-/// file.read_buf(&mut contents)
-/// .map(|res| {
-/// println!("{:?}", res);
-/// })
-/// }).map_err(|err| eprintln!("IO error: {:?}", err));
-/// tokio::run(task);
-/// }
+/// let task = tokio::fs::File::open("foo.txt")
+/// .and_then(|mut file| {
+/// let mut contents = vec![];
+/// file.read_buf(&mut contents)
+/// .map(|res| {
+/// println!("{:?}", res);
+/// })
+/// }).map_err(|err| eprintln!("IO error: {:?}", err));
+///
+/// tokio::run(task);
/// ```
#[derive(Debug)]
pub struct File {
@@ -98,18 +89,17 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
- /// fn main() {
- /// let task = tokio::fs::File::open("foo.txt").and_then(|file| {
- /// // do something with the file ...
- /// file.metadata().map(|md| println!("{:?}", md))
- /// }).map_err(|e| {
- /// // handle errors
- /// eprintln!("IO error: {:?}", e);
- /// });
- /// tokio::run(task);
- /// }
+ ///
+ /// let task = tokio::fs::File::open("foo.txt").and_then(|file| {
+ /// // do something with the file ...
+ /// file.metadata().map(|md| println!("{:?}", md))
+ /// }).map_err(|e| {
+ /// // handle errors
+ /// eprintln!("IO error: {:?}", e);
+ /// });
+ ///
+ /// tokio::run(task);
/// ```
pub fn open<P>(path: P) -> OpenFuture<P>
where
@@ -137,19 +127,18 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|file| {
- /// // do something with the created file ...
- /// file.metadata().map(|md| println!("{:?}", md))
- /// }).map_err(|e| {
- /// // handle errors
- /// eprintln!("IO error: {:?}", e);
- /// });
- /// tokio::run(task);
- /// }
+ ///
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|file| {
+ /// // do something with the created file ...
+ /// file.metadata().map(|md| println!("{:?}", md))
+ /// }).map_err(|e| {
+ /// // handle errors
+ /// eprintln!("IO error: {:?}", e);
+ /// });
+ ///
+ /// tokio::run(task);
/// ```
pub fn create<P>(path: P) -> CreateFuture<P>
where
@@ -165,13 +154,10 @@ impl File {
///
/// Examples
/// ```no_run
- /// # extern crate tokio;
/// use std::fs::File;
///
- /// fn main() {
- /// let std_file = File::open("foo.txt").unwrap();
- /// let file = tokio::fs::File::from_std(std_file);
- /// }
+ /// let std_file = File::open("foo.txt").unwrap();
+ /// let file = tokio::fs::File::from_std(std_file);
/// ```
pub fn from_std(std: StdFile) -> File {
File { std: Some(std) }
@@ -193,23 +179,20 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
/// use std::io::SeekFrom;
///
- /// fn main() {
- /// let task = tokio::fs::File::open("foo.txt")
- /// // move cursor 6 bytes from the start of the file
- /// .and_then(|mut file| file.poll_seek(SeekFrom::Start(6)))
- /// .map(|res| {
- /// println!("{:?}", res);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ /// let task = tokio::fs::File::open("foo.txt")
+ /// // move cursor 6 bytes from the start of the file
+ /// .and_then(|mut file| file.poll_seek(SeekFrom::Start(6)))
+ /// .map(|res| {
+ /// println!("{:?}", res);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
- /// tokio::run(task);
- /// }
+ /// tokio::run(task);
/// ```
pub fn poll_seek(&mut self, pos: io::SeekFrom) -> Poll<u64, io::Error> {
- ::blocking_io(|| self.std().seek(pos))
+ crate::blocking_io(|| self.std().seek(pos))
}
/// Seek to an offset, in bytes, in a stream.
@@ -222,20 +205,17 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
/// use std::io::SeekFrom;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|file| file.seek(SeekFrom::Start(6)))
- /// .map(|file| {
- /// // handle returned file ..
- /// # println!("{:?}", file);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|file| file.seek(SeekFrom::Start(6)))
+ /// .map(|file| {
+ /// // handle returned file ..
+ /// # println!("{:?}", file);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
- /// tokio::run(task);
- /// }
+ /// tokio::run(task);
/// ```
pub fn seek(self, pos: io::SeekFrom) -> SeekFuture {
SeekFuture::new(self, pos)
@@ -249,25 +229,22 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::{AsyncWrite, Future};
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|mut file| {
- /// file.poll_write(b"hello, world!")?;
- /// file.poll_sync_all()
- /// })
- /// .map(|res| {
- /// // handle returned result ..
- /// # println!("{:?}", res);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
- ///
- /// tokio::run(task);
- /// }
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|mut file| {
+ /// file.poll_write(b"hello, world!")?;
+ /// file.poll_sync_all()
+ /// })
+ /// .map(|res| {
+ /// // handle returned result ..
+ /// # println!("{:?}", res);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ ///
+ /// tokio::run(task);
/// ```
pub fn poll_sync_all(&mut self) -> Poll<(), io::Error> {
- ::blocking_io(|| self.std().sync_all())
+ crate::blocking_io(|| self.std().sync_all())
}
/// This function is similar to `poll_sync_all`, except that it may not
@@ -282,25 +259,22 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::{AsyncWrite, Future};
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|mut file| {
- /// file.poll_write(b"hello, world!")?;
- /// file.poll_sync_data()
- /// })
- /// .map(|res| {
- /// // handle returned result ..
- /// # println!("{:?}", res);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
- ///
- /// tokio::run(task);
- /// }
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|mut file| {
+ /// file.poll_write(b"hello, world!")?;
+ /// file.poll_sync_data()
+ /// })
+ /// .map(|res| {
+ /// // handle returned result ..
+ /// # println!("{:?}", res);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ ///
+ /// tokio::run(task);
/// ```
pub fn poll_sync_data(&mut self) -> Poll<(), io::Error> {
- ::blocking_io(|| self.std().sync_data())
+ crate::blocking_io(|| self.std().sync_data())
}
/// Truncates or extends the underlying file, updating the size of this file to become size.
@@ -318,24 +292,21 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|mut file| {
- /// file.poll_set_len(10)
- /// })
- /// .map(|res| {
- /// // handle returned result ..
- /// # println!("{:?}", res);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
- ///
- /// tokio::run(task);
- /// }
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|mut file| {
+ /// file.poll_set_len(10)
+ /// })
+ /// .map(|res| {
+ /// // handle returned result ..
+ /// # println!("{:?}", res);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ ///
+ /// tokio::run(task);
/// ```
pub fn poll_set_len(&mut self, size: u64) -> Poll<(), io::Error> {
- ::blocking_io(|| self.std().set_len(size))
+ crate::blocking_io(|| self.std().set_len(size))
}
/// Queries metadata about the underlying file.
@@ -343,18 +314,15 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|file| file.metadata())
- /// .map(|metadata| {
- /// println!("{:?}", metadata);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|file| file.metadata())
+ /// .map(|metadata| {
+ /// println!("{:?}", metadata);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
- /// tokio::run(task);
- /// }
+ /// tokio::run(task);
/// ```
pub fn metadata(self) -> MetadataFuture {
MetadataFuture::new(self)
@@ -365,22 +333,19 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|mut file| file.poll_metadata())
- /// .map(|metadata| {
- /// // metadata is of type Async::Ready<Metadata>
- /// println!("{:?}", metadata);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|mut file| file.poll_metadata())
+ /// .map(|metadata| {
+ /// // metadata is of type Async::Ready<Metadata>
+ /// println!("{:?}", metadata);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
- /// tokio::run(task);
- /// }
+ /// tokio::run(task);
/// ```
pub fn poll_metadata(&mut self) -> Poll<Metadata, io::Error> {
- ::blocking_io(|| self.std().metadata())
+ crate::blocking_io(|| self.std().metadata())
}
/// Create a new `File` instance that shares the same underlying file handle
@@ -390,22 +355,19 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|mut file| file.poll_try_clone())
- /// .map(|clone| {
- /// // do something with the clone
- /// # println!("{:?}", clone);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|mut file| file.poll_try_clone())
+ /// .map(|clone| {
+ /// // do something with the clone
+ /// # println!("{:?}", clone);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
- /// tokio::run(task);
- /// }
+ /// tokio::run(task);
/// ```
pub fn poll_try_clone(&mut self) -> Poll<File, io::Error> {
- ::blocking_io(|| {
+ crate::blocking_io(|| {
let std = self.std().try_clone()?;
Ok(File::from_std(std))
})
@@ -416,28 +378,26 @@ impl File {
/// File instances simultaneously.
///
/// # Examples
+ ///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|file| {
- /// file.try_clone()
- /// .map(|(file, clone)| {
- /// // do something with the file and the clone
- /// # println!("{:?} {:?}", file, clone);
- /// })
- /// .map_err(|(file, err)| {
- /// // you get the original file back if there's an error
- /// # println!("{:?}", file);
- /// err
- /// })
- /// })
- /// .map_err(|err| eprintln!("IO error: {:?}", err));
- ///
- /// tokio::run(task);
- /// }
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|file| {
+ /// file.try_clone()
+ /// .map(|(file, clone)| {
+ /// // do something with the file and the clone
+ /// # println!("{:?} {:?}", file, clone);
+ /// })
+ /// .map_err(|(file, err)| {
+ /// // you get the original file back if there's an error
+ /// # println!("{:?}", file);
+ /// err
+ /// })
+ /// })
+ /// .map_err(|err| eprintln!("IO error: {:?}", err));
+ ///
+ /// tokio::run(task);
/// ```
pub fn try_clone(self) -> CloneFuture {
CloneFuture::new(self)
@@ -462,26 +422,23 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .and_then(|file| file.metadata())
- /// .map(|(mut file, metadata)| {
- /// let mut perms = metadata.permissions();
- /// perms.set_readonly(true);
- /// match file.poll_set_permissions(perms) {
- /// Err(e) => eprintln!("{}", e),
- /// _ => println!("permissions set!"),
- /// }
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
- ///
- /// tokio::run(task);
- /// }
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .and_then(|file| file.metadata())
+ /// .map(|(mut file, metadata)| {
+ /// let mut perms = metadata.permissions();
+ /// perms.set_readonly(true);
+ /// match file.poll_set_permissions(perms) {
+ /// Err(e) => eprintln!("{}", e),
+ /// _ => println!("permissions set!"),
+ /// }
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ ///
+ /// tokio::run(task);
/// ```
pub fn poll_set_permissions(&mut self, perm: Permissions) -> Poll<(), io::Error> {
- ::blocking_io(|| self.std().set_permissions(perm))
+ crate::blocking_io(|| self.std().set_permissions(perm))
}
/// Destructures the `tokio_fs::File` into a [`std::fs::File`][std].
@@ -495,19 +452,16 @@ impl File {
/// # Examples
///
/// ```no_run
- /// # extern crate tokio;
/// use tokio::prelude::Future;
///
- /// fn main() {
- /// let task = tokio::fs::File::create("foo.txt")
- /// .map(|file| {
- /// let std_file = file.into_std();
- /// // do something with the std::fs::File
- /// # println!("{:?}", std_file);
- /// }).map_err(|err| eprintln!("IO error: {:?}", err));
+ /// let task = tokio::fs::File::create("foo.txt")
+ /// .map(|file| {
+ /// let std_file = file.into_std();
+ /// // do something with the std::fs::File
+ /// # println!("{:?}", std_file);
+ /// }).map_err(|err| eprintln!("IO error: {:?}", err));
///
- /// tokio::run(task);
- /// }
+ /// tokio::run(task);
/// ```
pub fn into_std(mut self) -> StdFile {
self.std.take().expect("`File` instance already shutdown")
@@ -520,7 +474,7 @@ impl File {
impl Read for File {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
- ::would_block(|| self.std().read(buf))
+ crate::would_block(|| self.std().read(buf))
}
}
@@ -532,17 +486,17 @@ impl AsyncRead for File {
impl Write for File {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
- ::would_block(|| self.std().write(buf))
+ crate::would_block(|| self.std().write(buf))
}
fn flush(&mut self) -> io::Result<()> {
- ::would_block(|| self.std().flush())
+ crate::would_block(|| self.std().flush())
}
}
impl AsyncWrite for File {
fn shutdown(&mut self) -> Poll<(), io::Error> {
- ::blocking_io(|| {
+ crate::blocking_io(|| {
self.std = None;
Ok(())
})
diff --git a/tokio-fs/src/file/open.rs b/tokio-fs/src/file/open.rs
index 68f7abe3..b95af160 100644
--- a/tokio-fs/src/file/open.rs
+++ b/tokio-fs/src/file/open.rs
@@ -1,7 +1,5 @@
use super::File;
-
-use futures::{Future, Poll};
-
+use futures::{try_ready, Future, Poll};
use std::fs::OpenOptions as StdOpenOptions;
use std::io;
use std::path::Path;
@@ -30,7 +28,7 @@ where
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- let std = try_ready!(::blocking_io(|| self.options.open(&self.path)));
+ let std = try_ready!(crate::blocking_io(|| self.options.open(&self.path)));
let file = File::from_std(std);
Ok(file.into())
diff --git a/tokio-fs/src/file/open_options.rs b/tokio-fs/src/file/open_options.rs
index 76e0678b..70b78211 100644
--- a/tokio-fs/src/file/open_options.rs
+++ b/tokio-fs/src/file/open_options.rs
@@ -1,5 +1,4 @@
use super::OpenFuture;
-
use std::convert::From;
use std::fs::OpenOptions as StdOpenOptions;
use std::path::Path;
diff --git a/tokio-fs/src/file/seek.rs b/tokio-fs/src/file/seek.rs
index 373e53ce..16f30e1b 100644
--- a/tokio-fs/src/file/seek.rs
+++ b/tokio-fs/src/file/seek.rs
@@ -1,7 +1,5 @@
use super::File;
-
-use futures::{Future, Poll};
-
+use futures::{try_ready, Future, Poll};
use std::io;
/// Future returned by `File::seek`.
diff --git a/tokio-fs/src/hard_link.rs b/tokio-fs/src/hard_link.rs
index 69742790..277eedbe 100644
--- a/tokio-fs/src/hard_link.rs
+++ b/tokio-fs/src/hard_link.rs
@@ -1,9 +1,8 @@
+use futures::{Future, Poll};
use std::fs;
use std::io;
use std::path::Path;
-use futures::{Future, Poll};
-
/// Creates a new hard link on the filesystem.
///
/// The `dst` path will be a link pointing to the `src` path. Note that systems
@@ -46,6 +45,6 @@ where
type Error = io::Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
- ::blocking_io(|| fs::hard_link(&self.src, &self.dst))
+ crate::blocking_io(|| fs::hard_link(&self.src, &self.dst))
}
}
diff --git a/tokio-fs/src/lib.rs b/tokio-fs/src/lib.rs
index ba6a9585..89b95623 100644
--- a/tokio-fs/src/lib.rs
+++ b/tokio-fs/src/lib.rs
@@ -1,5 +1,7 @@
-#![deny(missing_docs, missing_debug_implementations, warnings)]
#![doc(html_root_url = "https://docs.rs/tokio-fs/0.1.6")]
+#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)]
+#![cfg_attr(test, deny(warnings))]
+#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
//! Asynchronous file and standard stream adaptation.
//!
@@ -28,11 +30,6 @@
//! [`AsyncRead`]: https://docs.rs/tokio-io/0.1/tokio_io/trait.AsyncRead.html
//! [tokio-threadpool]: https://docs.rs/tokio-threadpool/0.1/tokio_threadpool
-#[macro_use]
-extern crate futures;
-extern crate tokio_io;
-extern crate tokio_threadpool;
-
mod create_dir;
mod create_dir_all;
pub mod file;
@@ -52,28 +49,27 @@ mod stdout;
mod symlink_metadata;
mod write;
-pub use create_dir::{create_dir, CreateDirFuture};
-pub use create_dir_all::{create_dir_all, CreateDirAllFuture};
-pub use file::File;
-pub use file::OpenOptions;