diff --git a/tokio-fs/src/lib.rs b/tokio-fs/src/lib.rs index 71fc35af5..563633a19 100644 --- a/tokio-fs/src/lib.rs +++ b/tokio-fs/src/lib.rs @@ -21,43 +21,23 @@ extern crate tokio_io; extern crate tokio_threadpool; pub mod file; +mod metadata; mod stdin; mod stdout; mod stderr; pub use file::File; pub use file::OpenOptions; +pub use metadata::{metadata, MetadataFuture}; pub use stdin::{stdin, Stdin}; pub use stdout::{stdout, Stdout}; pub use stderr::{stderr, Stderr}; -use futures::{Future, Poll}; +use futures::Poll; use futures::Async::*; -use std::fs::{self, Metadata}; use std::io; use std::io::ErrorKind::{Other, WouldBlock}; -use std::path::PathBuf; - -/// Queries the file system metadata for a path -pub fn metadata(path: PathBuf) -> MetadataFuture { - MetadataFuture { path } -} - -/// Future returned by `metadata` -#[derive(Debug)] -pub struct MetadataFuture { - path: PathBuf, -} - -impl Future for MetadataFuture { - type Item = Metadata; - type Error = io::Error; - - fn poll(&mut self) -> Poll { - blocking_io(|| fs::metadata(&self.path)) - } -} fn blocking_io(f: F) -> Poll where F: FnOnce() -> io::Result, diff --git a/tokio-fs/src/metadata.rs b/tokio-fs/src/metadata.rs new file mode 100644 index 000000000..9000cb1ba --- /dev/null +++ b/tokio-fs/src/metadata.rs @@ -0,0 +1,45 @@ +use super::blocking_io; + +use futures::{Future, Poll}; + +use std::fs::{self, Metadata}; +use std::io; +use std::path::Path; + +/// Queries the file system metadata for a path +pub fn metadata

(path: P) -> MetadataFuture

+where + P: AsRef + Send + 'static, +{ + MetadataFuture::new(path) +} + +/// Future returned by `metadata` +#[derive(Debug)] +pub struct MetadataFuture

+where + P: AsRef + Send + 'static, +{ + path: P, +} + +impl

MetadataFuture

+where + P: AsRef + Send + 'static, +{ + pub(crate) fn new(path: P) -> Self { + Self { path } + } +} + +impl

Future for MetadataFuture

+where + P: AsRef + Send + 'static, +{ + type Item = Metadata; + type Error = io::Error; + + fn poll(&mut self) -> Poll { + blocking_io(|| fs::metadata(&self.path)) + } +}