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

51 lines
1.1 KiB
Rust
Raw Normal View History

use super::blocking_io;
use std::fs::{self, Metadata};
2019-07-11 11:05:49 -05:00
use std::future::Future;
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;
/// Queries the file system metadata for a path.
///
/// This is an async version of [`std::fs::symlink_metadata`][std]
///
/// [std]: https://doc.rust-lang.org/std/fs/fn.symlink_metadata.html
pub fn symlink_metadata<P>(path: P) -> SymlinkMetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
SymlinkMetadataFuture::new(path)
}
/// Future returned by `symlink_metadata`.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct SymlinkMetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
path: P,
}
impl<P> SymlinkMetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
pub(crate) fn new(path: P) -> Self {
Self { path }
}
}
impl<P> Future for SymlinkMetadataFuture<P>
where
P: AsRef<Path> + Send + 'static,
{
2019-07-11 11:05:49 -05:00
type Output = io::Result<Metadata>;
2019-07-11 11:05:49 -05:00
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
blocking_io(|| fs::symlink_metadata(&self.path))
}
}