broker_tokio/fs/create_dir_all.rs
1use crate::fs::asyncify;
2
3use std::io;
4use std::path::Path;
5
6/// Recursively create a directory and all of its parent components if they
7/// are missing.
8///
9/// This is an async version of [`std::fs::create_dir_all`][std]
10///
11/// [std]: std::fs::create_dir_all
12///
13/// # Platform-specific behavior
14///
15/// This function currently corresponds to the `mkdir` function on Unix
16/// and the `CreateDirectory` function on Windows.
17/// Note that, this [may change in the future][changes].
18///
19/// [changes]: https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior
20///
21/// # Errors
22///
23/// This function will return an error in the following situations, but is not
24/// limited to just these cases:
25///
26/// * If any directory in the path specified by `path` does not already exist
27/// and it could not be created otherwise. The specific error conditions for
28/// when a directory is being created (after it is determined to not exist) are
29/// outlined by [`fs::create_dir`].
30///
31/// Notable exception is made for situations where any of the directories
32/// specified in the `path` could not be created as it was being created concurrently.
33/// Such cases are considered to be successful. That is, calling `create_dir_all`
34/// concurrently from multiple threads or processes is guaranteed not to fail
35/// due to a race condition with itself.
36///
37/// [`fs::create_dir`]: std::fs::create_dir
38///
39/// # Examples
40///
41/// ```no_run
42/// use tokio::fs;
43///
44/// #[tokio::main]
45/// async fn main() -> std::io::Result<()> {
46/// fs::create_dir_all("/some/dir").await?;
47/// Ok(())
48/// }
49/// ```
50pub async fn create_dir_all(path: impl AsRef<Path>) -> io::Result<()> {
51 let path = path.as_ref().to_owned();
52 asyncify(move || std::fs::create_dir_all(path)).await
53}