Skip to content

Commit 8e8c54a

Browse files
committed
Added the parapgrah to path::Path::is_file too
1 parent d25d6c5 commit 8e8c54a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libstd/path.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2506,12 +2506,17 @@ impl Path {
25062506
/// check errors, call [`fs::metadata`] and handle its Result. Then call
25072507
/// [`fs::Metadata::is_file`] if it was Ok.
25082508
///
2509-
/// Note that the explanation about using `open` instead of `is_file`
2510-
/// that is present in the [`fs::Metadata`] documentation also applies here.
2509+
/// When the goal is simply to read from (or write to) the source, the most
2510+
/// reliable way to test the source can be read (or written to) is to open
2511+
/// it. Only using `is_file` can break workflows like `diff <( prog_a )` on
2512+
/// a Unix-like system for example. See [`File::open`] or
2513+
/// [`OpenOptions::open`] for more information.
25112514
///
25122515
/// [`fs::metadata`]: ../../std/fs/fn.metadata.html
25132516
/// [`fs::Metadata`]: ../../std/fs/struct.Metadata.html
25142517
/// [`fs::Metadata::is_file`]: ../../std/fs/struct.Metadata.html#method.is_file
2518+
/// [`File::open`]: ../../std/fs/struct.File.html#method.open
2519+
/// [`OpenOptions::open`]: ../../std/fs/struct.OpenOptions.html#method.open
25152520
#[stable(feature = "path_ext", since = "1.5.0")]
25162521
pub fn is_file(&self) -> bool {
25172522
fs::metadata(self).map(|m| m.is_file()).unwrap_or(false)

0 commit comments

Comments
 (0)