@@ -1823,76 +1823,98 @@ impl Path {
1823
1823
}
1824
1824
1825
1825
1826
- /// Gets information on the file, directory, etc at this path .
1826
+ /// Query the file system to get information about a file, directory, etc.
1827
1827
///
1828
- /// Consult the `fs::metadata` documentation for more info.
1828
+ /// This function will traverse symbolic links to query information about the
1829
+ /// destination file.
1829
1830
///
1830
- /// This call preserves identical runtime/error semantics with
1831
- /// `fs::metadata`.
1831
+ /// This is an alias to `fs::metadata`.
1832
1832
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1833
1833
pub fn metadata ( & self ) -> io:: Result < fs:: Metadata > {
1834
1834
fs:: metadata ( self )
1835
1835
}
1836
1836
1837
- /// Gets information on the file, directory, etc at this path .
1837
+ /// Query the metadata about a file without following symlinks .
1838
1838
///
1839
- /// Consult the `fs::symlink_metadata` documentation for more info.
1840
- ///
1841
- /// This call preserves identical runtime/error semantics with
1842
- /// `fs::symlink_metadata`.
1839
+ /// This is an alias to `fs::symlink_metadata`.
1843
1840
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1844
1841
pub fn symlink_metadata ( & self ) -> io:: Result < fs:: Metadata > {
1845
1842
fs:: symlink_metadata ( self )
1846
1843
}
1847
1844
1848
- /// Returns the canonical form of a path, normalizing all components and
1849
- /// eliminate all symlinks .
1845
+ /// Returns the canonical form of the path with all intermediate components
1846
+ /// normalized and symbolic links resolved .
1850
1847
///
1851
- /// This call preserves identical runtime/error semantics with
1852
- /// `fs::canonicalize`.
1848
+ /// This is an alias to `fs::canonicalize`.
1853
1849
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1854
1850
pub fn canonicalize ( & self ) -> io:: Result < PathBuf > {
1855
1851
fs:: canonicalize ( self )
1856
1852
}
1857
1853
1858
- /// Reads the symlink at this path .
1854
+ /// Reads a symbolic link, returning the file that the link points to .
1859
1855
///
1860
- /// For more information see `fs::read_link`.
1856
+ /// This is an alias to `fs::read_link`.
1861
1857
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1862
1858
pub fn read_link ( & self ) -> io:: Result < PathBuf > {
1863
1859
fs:: read_link ( self )
1864
1860
}
1865
1861
1866
- /// Reads the directory at this path.
1862
+ /// Returns an iterator over the entries within a directory.
1863
+ ///
1864
+ /// The iterator will yield instances of `io::Result<DirEntry>`. New errors may
1865
+ /// be encountered after an iterator is initially constructed.
1867
1866
///
1868
- /// For more information see `fs::read_dir`.
1867
+ /// This is an alias to `fs::read_dir`.
1869
1868
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1870
1869
pub fn read_dir ( & self ) -> io:: Result < fs:: ReadDir > {
1871
1870
fs:: read_dir ( self )
1872
1871
}
1873
1872
1874
- /// Boolean value indicator whether the underlying file exists on the local
1875
- /// filesystem. Returns false in exactly the cases where `fs::metadata`
1876
- /// fails.
1873
+ /// Returns whether the path points at an existing entity.
1874
+ ///
1875
+ /// This function will traverse symbolic links to query information about the
1876
+ /// destination file. In case of broken symbolic links this will return `false`.
1877
+ ///
1878
+ /// # Examples
1879
+ ///
1880
+ /// ```no_run
1881
+ /// use std::path::Path;
1882
+ /// assert_eq!(Path::new("does_not_exist.txt").exists(), false);
1883
+ /// ```
1877
1884
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1878
1885
pub fn exists ( & self ) -> bool {
1879
1886
fs:: metadata ( self ) . is_ok ( )
1880
1887
}
1881
1888
1882
- /// Whether the underlying implementation (be it a file path, or something
1883
- /// else) points at a "regular file" on the FS. Will return false for paths
1884
- /// to non-existent locations or directories or other non-regular files
1885
- /// (named pipes, etc). Follows links when making this determination.
1889
+ /// Returns whether the path is pointing at a regular file.
1890
+ ///
1891
+ /// This function will traverse symbolic links to query information about the
1892
+ /// destination file. In case of broken symbolic links this will return `false`.
1893
+ ///
1894
+ /// # Examples
1895
+ ///
1896
+ /// ```no_run
1897
+ /// use std::path::Path;
1898
+ /// assert_eq!(Path::new("./is_a_directory/").is_file(), false);
1899
+ /// assert_eq!(Path::new("a_file.txt").is_file(), true);
1900
+ /// ```
1886
1901
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1887
1902
pub fn is_file ( & self ) -> bool {
1888
1903
fs:: metadata ( self ) . map ( |m| m. is_file ( ) ) . unwrap_or ( false )
1889
1904
}
1890
1905
1891
- /// Whether the underlying implementation (be it a file path, or something
1892
- /// else) is pointing at a directory in the underlying FS. Will return
1893
- /// false for paths to non-existent locations or if the item is not a
1894
- /// directory (eg files, named pipes, etc). Follows links when making this
1895
- /// determination.
1906
+ /// Returns whether the path is pointing at a directory.
1907
+ ///
1908
+ /// This function will traverse symbolic links to query information about the
1909
+ /// destination file. In case of broken symbolic links this will return `false`.
1910
+ ///
1911
+ /// # Examples
1912
+ ///
1913
+ /// ```no_run
1914
+ /// use std::path::Path;
1915
+ /// assert_eq!(Path::new("./is_a_directory/").is_dir(), true);
1916
+ /// assert_eq!(Path::new("a_file.txt").is_dir(), false);
1917
+ /// ```
1896
1918
#[ stable( feature = "path_ext" , since = "1.5.0" ) ]
1897
1919
pub fn is_dir ( & self ) -> bool {
1898
1920
fs:: metadata ( self ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
0 commit comments