tokio_fs/
create_dir_all.rs

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