]> git.lizzy.rs Git - rust.git/commitdiff
Added the parapgrah to path::Path::is_file too
authorAlexis Bourget <alexis.bourget@gmail.com>
Sat, 27 Jun 2020 20:59:47 +0000 (22:59 +0200)
committerAlexis Bourget <alexis.bourget@gmail.com>
Sat, 27 Jun 2020 20:59:47 +0000 (22:59 +0200)
src/libstd/path.rs

index fa54b2063b424c711f02920601590ddf7bb3173a..f14a9ff72f62f473ef8437ed5c63650cbab30785 100644 (file)
@@ -2506,12 +2506,17 @@ pub fn exists(&self) -> bool {
     /// check errors, call [`fs::metadata`] and handle its Result. Then call
     /// [`fs::Metadata::is_file`] if it was Ok.
     ///
-    /// Note that the explanation about using `open` instead of `is_file`
-    /// that is present in the [`fs::Metadata`] documentation also applies here.
+    /// When the goal is simply to read from (or write to) the source, the most
+    /// reliable way to test the source can be read (or written to) is to open
+    /// it. Only using `is_file` can break workflows like `diff <( prog_a )` on
+    /// a Unix-like system for example. See [`File::open`] or
+    /// [`OpenOptions::open`] for more information.
     ///
     /// [`fs::metadata`]: ../../std/fs/fn.metadata.html
     /// [`fs::Metadata`]: ../../std/fs/struct.Metadata.html
     /// [`fs::Metadata::is_file`]: ../../std/fs/struct.Metadata.html#method.is_file
+    /// [`File::open`]: ../../std/fs/struct.File.html#method.open
+    /// [`OpenOptions::open`]: ../../std/fs/struct.OpenOptions.html#method.open
     #[stable(feature = "path_ext", since = "1.5.0")]
     pub fn is_file(&self) -> bool {
         fs::metadata(self).map(|m| m.is_file()).unwrap_or(false)