tokio_fs/
read_link.rs

1use std::fs;
2use std::io;
3use std::path::{Path, PathBuf};
4
5use futures::{Future, Poll};
6
7/// Reads a symbolic link, returning the file that the link points to.
8///
9/// This is an async version of [`std::fs::read_link`][std]
10///
11/// [std]: https://doc.rust-lang.org/std/fs/fn.read_link.html
12pub fn read_link<P: AsRef<Path>>(path: P) -> ReadLinkFuture<P> {
13    ReadLinkFuture::new(path)
14}
15
16/// Future returned by `read_link`.
17#[derive(Debug)]
18pub struct ReadLinkFuture<P>
19where
20    P: AsRef<Path>,
21{
22    path: P,
23}
24
25impl<P> ReadLinkFuture<P>
26where
27    P: AsRef<Path>,
28{
29    fn new(path: P) -> ReadLinkFuture<P> {
30        ReadLinkFuture { path: path }
31    }
32}
33
34impl<P> Future for ReadLinkFuture<P>
35where
36    P: AsRef<Path>,
37{
38    type Item = PathBuf;
39    type Error = io::Error;
40
41    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
42        ::blocking_io(|| fs::read_link(&self.path))
43    }
44}