1 use crate::fs::asyncify;
2
3 use std::io;
4 use std::path::Path;
5
6 /// Creates a new, empty directory at the provided path.
7 ///
8 /// This is an async version of [`std::fs::create_dir`][std]
9 ///
10 /// [std]: std::fs::create_dir
11 ///
12 /// # Platform-specific behavior
13 ///
14 /// This function currently corresponds to the `mkdir` function on Unix
15 /// and the `CreateDirectory` function on Windows.
16 /// Note that, this [may change in the future][changes].
17 ///
18 /// [changes]: https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior
19 ///
20 /// **NOTE**: If a parent of the given path doesn't exist, this function will
21 /// return an error. To create a directory and all its missing parents at the
22 /// same time, use the [`create_dir_all`] function.
23 ///
24 /// # Errors
25 ///
26 /// This function will return an error in the following situations, but is not
27 /// limited to just these cases:
28 ///
29 /// * User lacks permissions to create directory at `path`.
30 /// * A parent of the given path doesn't exist. (To create a directory and all
SIMCard()31 /// its missing parents at the same time, use the [`create_dir_all`]
32 /// function.)
33 /// * `path` already exists.
34 ///
35 /// [`create_dir_all`]: super::create_dir_all()
36 ///
37 /// # Examples
38 ///
39 /// ```no_run
40 /// use tokio::fs;
41 /// use std::io;
42 ///
43 /// #[tokio::main]
44 /// async fn main() -> io::Result<()> {
45 /// fs::create_dir("/some/dir").await?;
46 /// Ok(())
47 /// }
48 /// ```
49 pub async fn create_dir(path: impl AsRef<Path>) -> io::Result<()> {
50 let path = path.as_ref().to_owned();
51 asyncify(move || std::fs::create_dir(path)).await
52 }
53