Skip to content

Commit a01c91c

Browse files
committed
Document error coercion to false in path-ext methods + see also sections
1 parent f590a44 commit a01c91c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/libstd/path.rs

+34
Original file line numberDiff line numberDiff line change
@@ -2215,12 +2215,22 @@ impl Path {
22152215
/// This function will traverse symbolic links to query information about the
22162216
/// destination file. In case of broken symbolic links this will return `false`.
22172217
///
2218+
/// If you cannot access the directory containing the file, e.g. because of a
2219+
/// permission error, this will return `false`.
2220+
///
22182221
/// # Examples
22192222
///
22202223
/// ```no_run
22212224
/// use std::path::Path;
22222225
/// assert_eq!(Path::new("does_not_exist.txt").exists(), false);
22232226
/// ```
2227+
///
2228+
/// # See Also
2229+
///
2230+
/// This is a convenience function that coerces errors to false. If you want to
2231+
/// check errors, call [fs::metadata].
2232+
///
2233+
/// [fs::metadata]: ../../std/fs/fn.metadata.html
22242234
#[stable(feature = "path_ext", since = "1.5.0")]
22252235
pub fn exists(&self) -> bool {
22262236
fs::metadata(self).is_ok()
@@ -2231,13 +2241,25 @@ impl Path {
22312241
/// This function will traverse symbolic links to query information about the
22322242
/// destination file. In case of broken symbolic links this will return `false`.
22332243
///
2244+
/// If you cannot access the directory containing the file, e.g. because of a
2245+
/// permission error, this will return `false`.
2246+
///
22342247
/// # Examples
22352248
///
22362249
/// ```no_run
22372250
/// use std::path::Path;
22382251
/// assert_eq!(Path::new("./is_a_directory/").is_file(), false);
22392252
/// assert_eq!(Path::new("a_file.txt").is_file(), true);
22402253
/// ```
2254+
///
2255+
/// # See Also
2256+
///
2257+
/// This is a convenience function that coerces errors to false. If you want to
2258+
/// check errors, call [fs::metadata] and handle its Result. Then call
2259+
/// [fs::Metadata::is_file] if it was Ok.
2260+
///
2261+
/// [fs::metadata]: ../../std/fs/fn.metadata.html
2262+
/// [fs::Metadata::is_file]: ../../std/fs/struct.Metadata.html#method.is_file
22412263
#[stable(feature = "path_ext", since = "1.5.0")]
22422264
pub fn is_file(&self) -> bool {
22432265
fs::metadata(self).map(|m| m.is_file()).unwrap_or(false)
@@ -2248,13 +2270,25 @@ impl Path {
22482270
/// This function will traverse symbolic links to query information about the
22492271
/// destination file. In case of broken symbolic links this will return `false`.
22502272
///
2273+
/// If you cannot access the directory containing the file, e.g. because of a
2274+
/// permission error, this will return `false`.
2275+
///
22512276
/// # Examples
22522277
///
22532278
/// ```no_run
22542279
/// use std::path::Path;
22552280
/// assert_eq!(Path::new("./is_a_directory/").is_dir(), true);
22562281
/// assert_eq!(Path::new("a_file.txt").is_dir(), false);
22572282
/// ```
2283+
///
2284+
/// # See Also
2285+
///
2286+
/// This is a convenience function that coerces errors to false. If you want to
2287+
/// check errors, call [fs::metadata] and handle its Result. Then call
2288+
/// [fs::Metadata::is_dir] if it was Ok.
2289+
///
2290+
/// [fs::metadata]: ../../std/fs/fn.metadata.html
2291+
/// [fs::Metadata::is_dir]: ../../std/fs/struct.Metadata.html#method.is_dir
22582292
#[stable(feature = "path_ext", since = "1.5.0")]
22592293
pub fn is_dir(&self) -> bool {
22602294
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)

0 commit comments

Comments
 (0)