Files
tokio/tokio-fs/src/metadata.rs
T

48 lines
970 B
Rust
Raw Normal View History

2018-06-21 18:41:39 +02:00
use super::blocking_io;
2018-06-21 18:41:39 +02:00
use std::fs::{self, Metadata};
2019-07-11 11:05:49 -05:00
use std::future::Future;
2018-06-21 18:41:39 +02:00
use std::io;
use std::path::Path;
2019-07-11 11:05:49 -05:00
use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
2018-06-21 18:41:39 +02:00
2018-07-12 00:09:37 +02:00
/// Queries the file system metadata for a path.
2018-06-21 18:41:39 +02:00
pub fn metadata<P>(path: P) -> MetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
MetadataFuture::new(path)
}
2018-07-12 00:09:37 +02:00
/// Future returned by `metadata`.
2018-06-21 18:41:39 +02:00
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
2018-06-21 18:41:39 +02:00
pub struct MetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
path: P,
}
impl<P> MetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
pub(crate) fn new(path: P) -> Self {
Self { path }
}
}
impl<P> Future for MetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
2019-07-11 11:05:49 -05:00
type Output = io::Result<Metadata>;
2018-06-21 18:41:39 +02:00
2019-07-11 11:05:49 -05:00
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
2018-06-21 18:41:39 +02:00
blocking_io(|| fs::metadata(&self.path))
}
}