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))
}
}