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