tokio_fs/os/
unix.rs

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