tokio_fs/os/windows/
symlink_dir.rs

1use std::io;
2use std::os::windows::fs;
3use std::path::Path;
4
5use futures::{Future, Poll};
6
7/// Creates a new directory symlink on the filesystem.
8///
9/// The `dst` path will be a directory symbolic link pointing to the `src`
10/// path.
11///
12/// This is an async version of [`std::os::windows::fs::symlink_dir`][std]
13///
14/// [std]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_dir.html
15pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> SymlinkDirFuture<P, Q> {
16    SymlinkDirFuture::new(src, dst)
17}
18
19/// Future returned by `symlink_dir`.
20#[derive(Debug)]
21pub struct SymlinkDirFuture<P, Q>
22where
23    P: AsRef<Path>,
24    Q: AsRef<Path>,
25{
26    src: P,
27    dst: Q,
28}
29
30impl<P, Q> SymlinkDirFuture<P, Q>
31where
32    P: AsRef<Path>,
33    Q: AsRef<Path>,
34{
35    fn new(src: P, dst: Q) -> SymlinkDirFuture<P, Q> {
36        SymlinkDirFuture { src: src, dst: dst }
37    }
38}
39
40impl<P, Q> Future for SymlinkDirFuture<P, Q>
41where
42    P: AsRef<Path>,
43    Q: AsRef<Path>,
44{
45    type Item = ();
46    type Error = io::Error;
47
48    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
49        ::blocking_io(|| fs::symlink_dir(&self.src, &self.dst))
50    }
51}