| 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 | } |
| 24 | |
| 25 | impl FileType { |
| 26 | /// Returns `true` if this file type represents a regular directory. |
| 27 | /// |
| 28 | /// If this file type represents a symbolic link, this method returns `false`. |
| 29 | /// |
| 30 | /// # Examples |
| 31 | /// |
| 32 | /// ```no_run |
| 33 | /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { |
| 34 | /// # |
| 35 | /// use async_std::fs; |
| 36 | /// |
| 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 | unreachable!("this impl only appears in the rendered docs" ) |
| 44 | } |
| 45 | |
| 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 | unreachable!("this impl only appears in the rendered docs" ) |
| 64 | } |
| 65 | |
| 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 | unreachable!("this impl only appears in the rendered docs" ) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |