|
1 |
| -use cfg_if::cfg_if; |
| 1 | +cfg_not_docs! { |
| 2 | + pub use std::fs::FileType; |
| 3 | +} |
| 4 | + |
| 5 | +cfg_docs! { |
| 6 | + /// The type of a file or directory. |
| 7 | + /// |
| 8 | + /// A file type is returned by [`Metadata::file_type`]. |
| 9 | + /// |
| 10 | + /// Note that file types are mutually exclusive, i.e. at most one of methods [`is_dir`], |
| 11 | + /// [`is_file`], and [`is_symlink`] can return `true`. |
| 12 | + /// |
| 13 | + /// This type is a re-export of [`std::fs::FileType`]. |
| 14 | + /// |
| 15 | + /// [`Metadata::file_type`]: struct.Metadata.html#method.file_type |
| 16 | + /// [`is_dir`]: #method.is_dir |
| 17 | + /// [`is_file`]: #method.is_file |
| 18 | + /// [`is_symlink`]: #method.is_symlink |
| 19 | + /// [`std::fs::FileType`]: https://doc.rust-lang.org/std/fs/struct.FileType.html |
| 20 | + #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
| 21 | + pub struct FileType { |
| 22 | + _private: (), |
| 23 | + } |
2 | 24 |
|
3 |
| -cfg_if! { |
4 |
| - if #[cfg(feature = "docs")] { |
5 |
| - /// The type of a file or directory. |
| 25 | + impl FileType { |
| 26 | + /// Returns `true` if this file type represents a regular directory. |
6 | 27 | ///
|
7 |
| - /// A file type is returned by [`Metadata::file_type`]. |
| 28 | + /// If this file type represents a symbolic link, this method returns `false`. |
8 | 29 | ///
|
9 |
| - /// Note that file types are mutually exclusive, i.e. at most one of methods [`is_dir`], |
10 |
| - /// [`is_file`], and [`is_symlink`] can return `true`. |
| 30 | + /// # Examples |
11 | 31 | ///
|
12 |
| - /// This type is a re-export of [`std::fs::FileType`]. |
| 32 | + /// ```no_run |
| 33 | + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
| 34 | + /// # |
| 35 | + /// use async_std::fs; |
13 | 36 | ///
|
14 |
| - /// [`Metadata::file_type`]: struct.Metadata.html#method.file_type |
15 |
| - /// [`is_dir`]: #method.is_dir |
16 |
| - /// [`is_file`]: #method.is_file |
17 |
| - /// [`is_symlink`]: #method.is_symlink |
18 |
| - /// [`std::fs::FileType`]: https://doc.rust-lang.org/std/fs/struct.FileType.html |
19 |
| - #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
20 |
| - pub struct FileType { |
21 |
| - _private: (), |
| 37 | + /// let file_type = fs::metadata(".").await?.file_type(); |
| 38 | + /// println!("{:?}", file_type.is_dir()); |
| 39 | + /// # |
| 40 | + /// # Ok(()) }) } |
| 41 | + /// ``` |
| 42 | + pub fn is_dir(&self) -> bool { |
| 43 | + unimplemented!() |
22 | 44 | }
|
23 | 45 |
|
24 |
| - impl FileType { |
25 |
| - /// Returns `true` if this file type represents a regular directory. |
26 |
| - /// |
27 |
| - /// If this file type represents a symbolic link, this method returns `false`. |
28 |
| - /// |
29 |
| - /// # Examples |
30 |
| - /// |
31 |
| - /// ```no_run |
32 |
| - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
33 |
| - /// # |
34 |
| - /// use async_std::fs; |
35 |
| - /// |
36 |
| - /// let file_type = fs::metadata(".").await?.file_type(); |
37 |
| - /// println!("{:?}", file_type.is_dir()); |
38 |
| - /// # |
39 |
| - /// # Ok(()) }) } |
40 |
| - /// ``` |
41 |
| - pub fn is_dir(&self) -> bool { |
42 |
| - unimplemented!() |
43 |
| - } |
44 |
| - |
45 |
| - /// Returns `true` if this file type represents a regular file. |
46 |
| - /// |
47 |
| - /// If this file type represents a symbolic link, this method returns `false`. |
48 |
| - /// |
49 |
| - /// # Examples |
50 |
| - /// |
51 |
| - /// ```no_run |
52 |
| - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
53 |
| - /// # |
54 |
| - /// use async_std::fs; |
55 |
| - /// |
56 |
| - /// let file_type = fs::metadata("a.txt").await?.file_type(); |
57 |
| - /// println!("{:?}", file_type.is_file()); |
58 |
| - /// # |
59 |
| - /// # Ok(()) }) } |
60 |
| - /// ``` |
61 |
| - pub fn is_file(&self) -> bool { |
62 |
| - unimplemented!() |
63 |
| - } |
| 46 | + /// Returns `true` if this file type represents a regular file. |
| 47 | + /// |
| 48 | + /// If this file type represents a symbolic link, this method returns `false`. |
| 49 | + /// |
| 50 | + /// # Examples |
| 51 | + /// |
| 52 | + /// ```no_run |
| 53 | + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
| 54 | + /// # |
| 55 | + /// use async_std::fs; |
| 56 | + /// |
| 57 | + /// let file_type = fs::metadata("a.txt").await?.file_type(); |
| 58 | + /// println!("{:?}", file_type.is_file()); |
| 59 | + /// # |
| 60 | + /// # Ok(()) }) } |
| 61 | + /// ``` |
| 62 | + pub fn is_file(&self) -> bool { |
| 63 | + unimplemented!() |
| 64 | + } |
64 | 65 |
|
65 |
| - /// Returns `true` if this file type represents a symbolic link. |
66 |
| - /// |
67 |
| - /// # Examples |
68 |
| - /// |
69 |
| - /// ```no_run |
70 |
| - /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
71 |
| - /// # |
72 |
| - /// use async_std::fs; |
73 |
| - /// |
74 |
| - /// let file_type = fs::metadata("a.txt").await?.file_type(); |
75 |
| - /// println!("{:?}", file_type.is_symlink()); |
76 |
| - /// # |
77 |
| - /// # Ok(()) }) } |
78 |
| - /// ``` |
79 |
| - pub fn is_symlink(&self) -> bool { |
80 |
| - unimplemented!() |
81 |
| - } |
| 66 | + /// Returns `true` if this file type represents a symbolic link. |
| 67 | + /// |
| 68 | + /// # Examples |
| 69 | + /// |
| 70 | + /// ```no_run |
| 71 | + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
| 72 | + /// # |
| 73 | + /// use async_std::fs; |
| 74 | + /// |
| 75 | + /// let file_type = fs::metadata("a.txt").await?.file_type(); |
| 76 | + /// println!("{:?}", file_type.is_symlink()); |
| 77 | + /// # |
| 78 | + /// # Ok(()) }) } |
| 79 | + /// ``` |
| 80 | + pub fn is_symlink(&self) -> bool { |
| 81 | + unimplemented!() |
82 | 82 | }
|
83 |
| - } else { |
84 |
| - pub use std::fs::FileType; |
85 | 83 | }
|
86 | 84 | }
|
0 commit comments