tokio_fs/
create_dir.rs

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