1- use std:: fs;
21use std:: path:: Path ;
32
43use cfg_if:: cfg_if;
@@ -7,21 +6,28 @@ use crate::future::Future;
76use crate :: io;
87use crate :: task:: blocking;
98
10- /// A builder for creating directories in various manners.
9+ /// A builder for creating directories with configurable options.
10+ ///
11+ /// For Unix-specific options, import the [`os::unix::fs::DirBuilderExt`] trait.
1112///
1213/// This type is an async version of [`std::fs::DirBuilder`].
1314///
15+ /// [`os::unix::fs::DirBuilderExt`]: ../os/unix/fs/trait.DirBuilderExt.html
1416/// [`std::fs::DirBuilder`]: https://doc.rust-lang.org/std/fs/struct.DirBuilder.html
1517#[ derive( Debug ) ]
1618pub struct DirBuilder {
19+ /// Set to `true` if non-existent parent directories should be created.
1720 recursive : bool ,
1821
22+ /// Unix mode for newly created directories.
1923 #[ cfg( unix) ]
2024 mode : Option < u32 > ,
2125}
2226
2327impl DirBuilder {
24- /// Creates a new builder with [`recursive`] set to `false`.
28+ /// Creates a blank set of options.
29+ ///
30+ /// The [`recursive`] option is initially set to `false`.
2531 ///
2632 /// [`recursive`]: #method.recursive
2733 ///
@@ -33,25 +39,24 @@ impl DirBuilder {
3339 /// let builder = DirBuilder::new();
3440 /// ```
3541 pub fn new ( ) -> DirBuilder {
42+ #[ cfg( not( unix) ) ]
43+ let builder = DirBuilder { recursive : false } ;
44+
3645 #[ cfg( unix) ]
3746 let builder = DirBuilder {
3847 recursive : false ,
3948 mode : None ,
4049 } ;
4150
42- #[ cfg( windows) ]
43- let builder = DirBuilder { recursive : false } ;
44-
4551 builder
4652 }
4753
4854 /// Sets the option for recursive mode.
4955 ///
50- /// This option, when `true`, means that all parent directories should be created recursively
51- /// if they don't exist. Parents are created with the same security settings and permissions as
52- /// the final directory.
56+ /// When set to `true`, this option means all parent directories should be created recursively
57+ /// if they don't exist. Parents are created with the same permissions as the final directory.
5358 ///
54- /// This option defaults to `false`.
59+ /// This option is initially set to `false`.
5560 ///
5661 /// # Examples
5762 ///
@@ -70,6 +75,14 @@ impl DirBuilder {
7075 ///
7176 /// It is considered an error if the directory already exists unless recursive mode is enabled.
7277 ///
78+ /// # Errors
79+ ///
80+ /// An error will be returned in the following situations:
81+ ///
82+ /// * `path` already points to an existing file or directory.
83+ /// * The current process lacks permissions to create the directory or its missing parents.
84+ /// * Some other I/O error occurred.
85+ ///
7386 /// # Examples
7487 ///
7588 /// ```no_run
@@ -79,13 +92,13 @@ impl DirBuilder {
7992 ///
8093 /// DirBuilder::new()
8194 /// .recursive(true)
82- /// .create("/tmp/foo/bar/baz ")
95+ /// .create("./some/directory ")
8396 /// .await?;
8497 /// #
8598 /// # Ok(()) }) }
8699 /// ```
87100 pub fn create < P : AsRef < Path > > ( & self , path : P ) -> impl Future < Output = io:: Result < ( ) > > {
88- let mut builder = fs:: DirBuilder :: new ( ) ;
101+ let mut builder = std :: fs:: DirBuilder :: new ( ) ;
89102 builder. recursive ( self . recursive ) ;
90103
91104 #[ cfg( unix) ]
0 commit comments