1use super::blocking_io;
2
3use futures::{Future, Poll};
4
5use std::fs::{self, Metadata};
6use std::io;
7use std::path::Path;
8
9pub fn metadata<P>(path: P) -> MetadataFuture<P>
11where
12 P: AsRef<Path> + Send + 'static,
13{
14 MetadataFuture::new(path)
15}
16
17#[derive(Debug)]
19pub struct MetadataFuture<P>
20where
21 P: AsRef<Path> + Send + 'static,
22{
23 path: P,
24}
25
26impl<P> MetadataFuture<P>
27where
28 P: AsRef<Path> + Send + 'static,
29{
30 pub(crate) fn new(path: P) -> Self {
31 Self { path }
32 }
33}
34
35impl<P> Future for MetadataFuture<P>
36where
37 P: AsRef<Path> + Send + 'static,
38{
39 type Item = Metadata;
40 type Error = io::Error;
41
42 fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
43 blocking_io(|| fs::metadata(&self.path))
44 }
45}