about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-10-22 16:28:45 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-10-25 09:36:32 -0700
commitff49733274f4af79362f9f9aaf16fb6032b2a06d (patch)
tree1444494b80a935ed2e0adc250d061ddefb292b29 /src/libstd/path.rs
parent9a855668fcc918071ecd1573abdeaccc6a99cbbb (diff)
downloadrust-ff49733274f4af79362f9f9aaf16fb6032b2a06d.tar.gz
rust-ff49733274f4af79362f9f9aaf16fb6032b2a06d.zip
std: Stabilize library APIs for 1.5
This commit stabilizes and deprecates library APIs whose FCP has closed in the
last cycle, specifically:

Stabilized APIs:

* `fs::canonicalize`
* `Path::{metadata, symlink_metadata, canonicalize, read_link, read_dir, exists,
   is_file, is_dir}` - all moved to inherent methods from the `PathExt` trait.
* `Formatter::fill`
* `Formatter::width`
* `Formatter::precision`
* `Formatter::sign_plus`
* `Formatter::sign_minus`
* `Formatter::alternate`
* `Formatter::sign_aware_zero_pad`
* `string::ParseError`
* `Utf8Error::valid_up_to`
* `Iterator::{cmp, partial_cmp, eq, ne, lt, le, gt, ge}`
* `<[T]>::split_{first,last}{,_mut}`
* `Condvar::wait_timeout` - note that `wait_timeout_ms` is not yet deprecated
  but will be once 1.5 is released.
* `str::{R,}MatchIndices`
* `str::{r,}match_indices`
* `char::from_u32_unchecked`
* `VecDeque::insert`
* `VecDeque::shrink_to_fit`
* `VecDeque::as_slices`
* `VecDeque::as_mut_slices`
* `VecDeque::swap_remove_front` - (renamed from `swap_front_remove`)
* `VecDeque::swap_remove_back` - (renamed from `swap_back_remove`)
* `Vec::resize`
* `str::slice_mut_unchecked`
* `FileTypeExt`
* `FileTypeExt::{is_block_device, is_char_device, is_fifo, is_socket}`
* `BinaryHeap::from` - `from_vec` deprecated in favor of this
* `BinaryHeap::into_vec` - plus a `Into` impl
* `BinaryHeap::into_sorted_vec`

Deprecated APIs

* `slice::ref_slice`
* `slice::mut_ref_slice`
* `iter::{range_inclusive, RangeInclusive}`
* `std::dynamic_lib`

Closes #27706
Closes #27725
cc #27726 (align not stabilized yet)
Closes #27734
Closes #27737
Closes #27742
Closes #27743
Closes #27772
Closes #27774
Closes #27777
Closes #27781
cc #27788 (a few remaining methods though)
Closes #27790
Closes #27793
Closes #27796
Closes #27810
cc #28147 (not all parts stabilized)
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 43c2766782e..fe12b671235 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -101,12 +101,14 @@
 use ascii::*;
 use borrow::{Borrow, IntoCow, ToOwned, Cow};
 use cmp;
+use fmt;
+use fs;
+use io;
 use iter;
 use mem;
 use ops::{self, Deref};
 use string::String;
 use vec::Vec;
-use fmt;
 
 use ffi::{OsStr, OsString};
 
@@ -1689,6 +1691,81 @@ impl Path {
     pub fn display(&self) -> Display {
         Display { path: self }
     }
+
+
+    /// Gets information on the file, directory, etc at this path.
+    ///
+    /// Consult the `fs::metadata` documentation for more info.
+    ///
+    /// This call preserves identical runtime/error semantics with
+    /// `fs::metadata`.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn metadata(&self) -> io::Result<fs::Metadata> {
+        fs::metadata(self)
+    }
+
+    /// Gets information on the file, directory, etc at this path.
+    ///
+    /// Consult the `fs::symlink_metadata` documentation for more info.
+    ///
+    /// This call preserves identical runtime/error semantics with
+    /// `fs::symlink_metadata`.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn symlink_metadata(&self) -> io::Result<fs::Metadata> {
+        fs::symlink_metadata(self)
+    }
+
+    /// Returns the canonical form of a path, normalizing all components and
+    /// eliminate all symlinks.
+    ///
+    /// This call preserves identical runtime/error semantics with
+    /// `fs::canonicalize`.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn canonicalize(&self) -> io::Result<PathBuf> {
+        fs::canonicalize(self)
+    }
+
+    /// Reads the symlink at this path.
+    ///
+    /// For more information see `fs::read_link`.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn read_link(&self) -> io::Result<PathBuf> {
+        fs::read_link(self)
+    }
+
+    /// Reads the directory at this path.
+    ///
+    /// For more information see `fs::read_dir`.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn read_dir(&self) -> io::Result<fs::ReadDir> {
+        fs::read_dir(self)
+    }
+
+    /// Boolean value indicator whether the underlying file exists on the local
+    /// filesystem. Returns false in exactly the cases where `fs::stat` fails.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn exists(&self) -> bool {
+        fs::metadata(self).is_ok()
+    }
+
+    /// Whether the underlying implementation (be it a file path, or something
+    /// else) points at a "regular file" on the FS. Will return false for paths
+    /// to non-existent locations or directories or other non-regular files
+    /// (named pipes, etc). Follows links when making this determination.
+    #[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)
+    }
+
+    /// Whether the underlying implementation (be it a file path, or something
+    /// else) is pointing at a directory in the underlying FS. Will return
+    /// false for paths to non-existent locations or if the item is not a
+    /// directory (eg files, named pipes, etc). Follows links when making this
+    /// determination.
+    #[stable(feature = "path_ext", since = "1.5.0")]
+    pub fn is_dir(&self) -> bool {
+        fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]