mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-30 00:00:16 +02:00
Update Tokio to Rust 2018 (#1082)
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::File;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
use std::io;
|
||||
|
||||
/// Future returned by `File::try_clone`.
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
+148
-194
@@ -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));
|
||||
/// 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);
|
||||
/// }
|
||||
/// 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));
|
||||
/// 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);
|
||||
/// }
|
||||
/// 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));
|
||||
/// 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);
|
||||
/// }
|
||||
/// 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));
|
||||
/// 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);
|
||||
/// }
|
||||
/// 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));
|
||||
/// 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);
|
||||
/// }
|
||||
/// 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(())
|
||||
})
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use super::OpenFuture;
|
||||
|
||||
use std::convert::From;
|
||||
use std::fs::OpenOptions as StdOpenOptions;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
+21
-25
@@ -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;
|
||||
pub use hard_link::{hard_link, HardLinkFuture};
|
||||
pub use metadata::{metadata, MetadataFuture};
|
||||
pub use read::{read, ReadFile};
|
||||
pub use read_dir::{read_dir, DirEntry, ReadDir, ReadDirFuture};
|
||||
pub use read_link::{read_link, ReadLinkFuture};
|
||||
pub use remove_dir::{remove_dir, RemoveDirFuture};
|
||||
pub use remove_file::{remove_file, RemoveFileFuture};
|
||||
pub use rename::{rename, RenameFuture};
|
||||
pub use set_permissions::{set_permissions, SetPermissionsFuture};
|
||||
pub use stderr::{stderr, Stderr};
|
||||
pub use stdin::{stdin, Stdin};
|
||||
pub use stdout::{stdout, Stdout};
|
||||
pub use symlink_metadata::{symlink_metadata, SymlinkMetadataFuture};
|
||||
pub use write::{write, WriteFile};
|
||||
pub use crate::create_dir::{create_dir, CreateDirFuture};
|
||||
pub use crate::create_dir_all::{create_dir_all, CreateDirAllFuture};
|
||||
pub use crate::file::File;
|
||||
pub use crate::file::OpenOptions;
|
||||
pub use crate::hard_link::{hard_link, HardLinkFuture};
|
||||
pub use crate::metadata::{metadata, MetadataFuture};
|
||||
pub use crate::read::{read, ReadFile};
|
||||
pub use crate::read_dir::{read_dir, DirEntry, ReadDir, ReadDirFuture};
|
||||
pub use crate::read_link::{read_link, ReadLinkFuture};
|
||||
pub use crate::remove_dir::{remove_dir, RemoveDirFuture};
|
||||
pub use crate::remove_file::{remove_file, RemoveFileFuture};
|
||||
pub use crate::rename::{rename, RenameFuture};
|
||||
pub use crate::set_permissions::{set_permissions, SetPermissionsFuture};
|
||||
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, SymlinkMetadataFuture};
|
||||
pub use crate::write::{write, WriteFile};
|
||||
|
||||
use futures::Async::*;
|
||||
use futures::Poll;
|
||||
|
||||
use std::io;
|
||||
use std::io::ErrorKind::{Other, WouldBlock};
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::blocking_io;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
use std::fs::{self, Metadata};
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
//! Unix-specific extensions to primitives in the `tokio_fs` module.
|
||||
|
||||
use futures::{Future, Poll};
|
||||
use std::io;
|
||||
use std::os::unix::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Creates a new symbolic link on the filesystem.
|
||||
///
|
||||
/// The `dst` path will be a symbolic link pointing to the `src` path.
|
||||
@@ -47,6 +46,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::symlink(&self.src, &self.dst))
|
||||
crate::blocking_io(|| fs::symlink(&self.src, &self.dst))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::io;
|
||||
use std::os::windows::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Creates a new directory symlink on the filesystem.
|
||||
///
|
||||
/// The `dst` path will be a directory symbolic link pointing to the `src`
|
||||
@@ -46,6 +45,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::symlink_dir(&self.src, &self.dst))
|
||||
crate::blocking_io(|| fs::symlink_dir(&self.src, &self.dst))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::io;
|
||||
use std::os::windows::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Creates a new file symbolic link on the filesystem.
|
||||
///
|
||||
/// The `dst` path will be a file symbolic link pointing to the `src`
|
||||
@@ -46,6 +45,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::symlink_file(&self.src, &self.dst))
|
||||
crate::blocking_io(|| fs::symlink_file(&self.src, &self.dst))
|
||||
}
|
||||
}
|
||||
|
||||
+12
-13
@@ -1,7 +1,7 @@
|
||||
use futures::{Async, Future, Poll};
|
||||
use crate::{file, File};
|
||||
use futures::{try_ready, Async, Future, Poll};
|
||||
use std::{io, mem, path::Path};
|
||||
use tokio_io;
|
||||
use {file, File};
|
||||
|
||||
/// Creates a future which will open a file for reading and read the entire
|
||||
/// contents into a buffer and return said buffer.
|
||||
@@ -11,18 +11,17 @@ use {file, File};
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # extern crate tokio;
|
||||
/// use tokio::prelude::Future;
|
||||
/// fn main() {
|
||||
/// let task = tokio::fs::read("foo.txt").map(|data| {
|
||||
/// // do something with the contents of the file ...
|
||||
/// println!("foo.txt contains {} bytes", data.len());
|
||||
/// }).map_err(|e| {
|
||||
/// // handle errors
|
||||
/// eprintln!("IO error: {:?}", e);
|
||||
/// });
|
||||
/// tokio::run(task);
|
||||
/// }
|
||||
///
|
||||
/// let task = tokio::fs::read("foo.txt").map(|data| {
|
||||
/// // do something with the contents of the file ...
|
||||
/// println!("foo.txt contains {} bytes", data.len());
|
||||
/// }).map_err(|e| {
|
||||
/// // handle errors
|
||||
/// eprintln!("IO error: {:?}", e);
|
||||
/// });
|
||||
///
|
||||
/// tokio::run(task);
|
||||
/// ```
|
||||
pub fn read<P>(path: P) -> ReadFile<P>
|
||||
where
|
||||
|
||||
+37
-54
@@ -1,3 +1,4 @@
|
||||
use futures::{Future, Poll, Stream};
|
||||
use std::ffi::OsString;
|
||||
use std::fs::{self, DirEntry as StdDirEntry, FileType, Metadata, ReadDir as StdReadDir};
|
||||
use std::io;
|
||||
@@ -5,8 +6,6 @@ use std::io;
|
||||
use std::os::unix::fs::DirEntryExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use futures::{Future, Poll, Stream};
|
||||
|
||||
/// Returns a stream over the entries within a directory.
|
||||
///
|
||||
/// This is an async version of [`std::fs::read_dir`][std]
|
||||
@@ -45,7 +44,7 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, io::Error> {
|
||||
::blocking_io(|| Ok(ReadDir(fs::read_dir(&self.path)?)))
|
||||
crate::blocking_io(|| Ok(ReadDir(fs::read_dir(&self.path)?)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +72,7 @@ impl Stream for ReadDir {
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
::blocking_io(|| match self.0.next() {
|
||||
crate::blocking_io(|| match self.0.next() {
|
||||
Some(Err(err)) => Err(err),
|
||||
Some(Ok(item)) => Ok(Some(DirEntry(item))),
|
||||
None => Ok(None),
|
||||
@@ -112,18 +111,14 @@ impl DirEntry {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio;
|
||||
/// # extern crate tokio_fs;
|
||||
/// use futures::{Future, Stream};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// println!("{:?}", dir.path());
|
||||
/// Ok(())
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
/// tokio::run(fut);
|
||||
/// }
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// println!("{:?}", dir.path());
|
||||
/// Ok(())
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
///
|
||||
/// tokio::run(fut);
|
||||
/// ```
|
||||
///
|
||||
/// This prints output like:
|
||||
@@ -145,19 +140,15 @@ impl DirEntry {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio;
|
||||
/// # extern crate tokio_fs;
|
||||
/// use futures::{Future, Stream};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// // Here, `dir` is a `DirEntry`.
|
||||
/// println!("{:?}", dir.file_name());
|
||||
/// Ok(())
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
/// tokio::run(fut);
|
||||
/// }
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// // Here, `dir` is a `DirEntry`.
|
||||
/// println!("{:?}", dir.file_name());
|
||||
/// Ok(())
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
///
|
||||
/// tokio::run(fut);
|
||||
/// ```
|
||||
pub fn file_name(&self) -> OsString {
|
||||
self.0.file_name()
|
||||
@@ -177,25 +168,21 @@ impl DirEntry {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio;
|
||||
/// # extern crate tokio_fs;
|
||||
/// use futures::{Future, Stream};
|
||||
/// use futures::future::poll_fn;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// // Here, `dir` is a `DirEntry`.
|
||||
/// let path = dir.path();
|
||||
/// poll_fn(move || dir.poll_metadata()).map(move |metadata| {
|
||||
/// println!("{:?}: {:?}", path, metadata.permissions());
|
||||
/// })
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
/// tokio::run(fut);
|
||||
/// }
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// // Here, `dir` is a `DirEntry`.
|
||||
/// let path = dir.path();
|
||||
/// poll_fn(move || dir.poll_metadata()).map(move |metadata| {
|
||||
/// println!("{:?}: {:?}", path, metadata.permissions());
|
||||
/// })
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
///
|
||||
/// tokio::run(fut);
|
||||
/// ```
|
||||
pub fn poll_metadata(&self) -> Poll<Metadata, io::Error> {
|
||||
::blocking_io(|| self.0.metadata())
|
||||
crate::blocking_io(|| self.0.metadata())
|
||||
}
|
||||
|
||||
/// Return the file type for the file that this entry points at.
|
||||
@@ -212,26 +199,22 @@ impl DirEntry {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate futures;
|
||||
/// # extern crate tokio;
|
||||
/// # extern crate tokio_fs;
|
||||
/// use futures::{Future, Stream};
|
||||
/// use futures::future::poll_fn;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// // Here, `dir` is a `DirEntry`.
|
||||
/// let path = dir.path();
|
||||
/// poll_fn(move || dir.poll_file_type()).map(move |file_type| {
|
||||
/// // Now let's show our entry's file type!
|
||||
/// println!("{:?}: {:?}", path, file_type);
|
||||
/// })
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
/// tokio::run(fut);
|
||||
/// }
|
||||
/// let fut = tokio_fs::read_dir(".").flatten_stream().for_each(|dir| {
|
||||
/// // Here, `dir` is a `DirEntry`.
|
||||
/// let path = dir.path();
|
||||
/// poll_fn(move || dir.poll_file_type()).map(move |file_type| {
|
||||
/// // Now let's show our entry's file type!
|
||||
/// println!("{:?}: {:?}", path, file_type);
|
||||
/// })
|
||||
/// }).map_err(|err| { eprintln!("Error: {:?}", err); () });
|
||||
///
|
||||
/// tokio::run(fut);
|
||||
/// ```
|
||||
pub fn poll_file_type(&self) -> Poll<FileType, io::Error> {
|
||||
::blocking_io(|| self.0.file_type())
|
||||
crate::blocking_io(|| self.0.file_type())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Reads a symbolic link, returning the file that the link points to.
|
||||
///
|
||||
/// This is an async version of [`std::fs::read_link`][std]
|
||||
@@ -39,6 +38,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::read_link(&self.path))
|
||||
crate::blocking_io(|| fs::read_link(&self.path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Removes an existing, empty directory.
|
||||
///
|
||||
/// This is an async version of [`std::fs::remove_dir`][std]
|
||||
@@ -39,6 +38,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::remove_dir(&self.path))
|
||||
crate::blocking_io(|| fs::remove_dir(&self.path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Removes a file from the filesystem.
|
||||
///
|
||||
/// Note that there is no
|
||||
@@ -43,6 +42,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::remove_file(&self.path))
|
||||
crate::blocking_io(|| fs::remove_file(&self.path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Rename a file or directory to a new name, replacing the original file if
|
||||
/// `to` already exists.
|
||||
///
|
||||
@@ -46,6 +45,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::rename(&self.from, &self.to))
|
||||
crate::blocking_io(|| fs::rename(&self.from, &self.to))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use futures::{Future, Poll};
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
/// Changes the permissions found on a file or a directory.
|
||||
///
|
||||
/// This is an async version of [`std::fs::set_permissions`][std]
|
||||
@@ -43,6 +42,6 @@ where
|
||||
type Error = io::Error;
|
||||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
::blocking_io(|| fs::set_permissions(&self.path, self.perm.clone()))
|
||||
crate::blocking_io(|| fs::set_permissions(&self.path, self.perm.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use tokio_io::AsyncWrite;
|
||||
|
||||
use futures::Poll;
|
||||
|
||||
use std::io::{self, Stderr as StdStderr, Write};
|
||||
use tokio_io::AsyncWrite;
|
||||
|
||||
/// A handle to the standard error stream of a process.
|
||||
///
|
||||
@@ -29,11 +27,11 @@ pub fn stderr() -> Stderr {
|
||||
|
||||
impl Write for Stderr {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use tokio_io::AsyncRead;
|
||||
|
||||
use std::io::{self, Read, Stdin as StdStdin};
|
||||
use tokio_io::AsyncRead;
|
||||
|
||||
/// A handle to the standard input stream of a process.
|
||||
///
|
||||
@@ -33,7 +32,7 @@ pub fn stdin() -> Stdin {
|
||||
|
||||
impl Read for Stdin {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
::would_block(|| self.std.read(buf))
|
||||
crate::would_block(|| self.std.read(buf))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use tokio_io::AsyncWrite;
|
||||
|
||||
use futures::Poll;
|
||||
|
||||
use std::io::{self, Stdout as StdStdout, Write};
|
||||
use tokio_io::AsyncWrite;
|
||||
|
||||
/// A handle to the standard output stream of a process.
|
||||
///
|
||||
@@ -29,11 +27,11 @@ pub fn stdout() -> Stdout {
|
||||
|
||||
impl Write for Stdout {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::blocking_io;
|
||||
|
||||
use futures::{Future, Poll};
|
||||
|
||||
use std::fs::{self, Metadata};
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
+14
-15
@@ -1,7 +1,7 @@
|
||||
use futures::{Async, Future, Poll};
|
||||
use crate::{file, File};
|
||||
use futures::{try_ready, Async, Future, Poll};
|
||||
use std::{fmt, io, mem, path::Path};
|
||||
use tokio_io;
|
||||
use {file, File};
|
||||
|
||||
/// Creates a future that will open a file for writing and write the entire
|
||||
/// contents of `contents` to it.
|
||||
@@ -11,20 +11,19 @@ use {file, File};
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # extern crate tokio;
|
||||
/// use tokio::prelude::Future;
|
||||
/// fn main() {
|
||||
/// let buffer = b"Hello world!";
|
||||
/// let task = tokio::fs::write("foo.txt", buffer).map(|data| {
|
||||
/// // `data` has now been written to foo.txt. The buffer is being
|
||||
/// // returned so it can be used for other things.
|
||||
/// println!("foo.txt now had {} bytes written to it", data.len());
|
||||
/// }).map_err(|e| {
|
||||
/// // handle errors
|
||||
/// eprintln!("IO error: {:?}", e);
|
||||
/// });
|
||||
/// tokio::run(task);
|
||||
/// }
|
||||
///
|
||||
/// let buffer = b"Hello world!";
|
||||
/// let task = tokio::fs::write("foo.txt", buffer).map(|data| {
|
||||
/// // `data` has now been written to foo.txt. The buffer is being
|
||||
/// // returned so it can be used for other things.
|
||||
/// println!("foo.txt now had {} bytes written to it", data.len());
|
||||
/// }).map_err(|e| {
|
||||
/// // handle errors
|
||||
/// eprintln!("IO error: {:?}", e);
|
||||
/// });
|
||||
///
|
||||
/// tokio::run(task);
|
||||
/// ```
|
||||
pub fn write<P, C: AsRef<[u8]>>(path: P, contents: C) -> WriteFile<P, C>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user