about summary refs log tree commit diff
path: root/src/libstd/path
diff options
context:
space:
mode:
authorJonathan S <gereeter@gmail.com>2014-04-20 23:59:12 -0500
committerJonathan S <gereeter@gmail.com>2014-04-28 16:45:36 -0500
commit03609e5a5e8bdca9452327d44e25407ce888d0bb (patch)
treeffef048a962111a82bdc86f7b060a8d2fa2c96f6 /src/libstd/path
parentf58a8c9d760aead49e138fa8045e229a47217644 (diff)
downloadrust-03609e5a5e8bdca9452327d44e25407ce888d0bb.tar.gz
rust-03609e5a5e8bdca9452327d44e25407ce888d0bb.zip
Deprecate the rev_iter pattern in all places where a DoubleEndedIterator is provided (everywhere but treemap)
This commit deprecates rev_iter, mut_rev_iter, move_rev_iter everywhere (except treemap) and also
deprecates related functions like rsplit, rev_components, and rev_str_components. In every case,
these functions can be replaced with the non-reversed form followed by a call to .rev(). To make this
more concrete, a translation table for all functional changes necessary follows:

* container.rev_iter() -> container.iter().rev()
* container.mut_rev_iter() -> container.mut_iter().rev()
* container.move_rev_iter() -> container.move_iter().rev()
* sliceorstr.rsplit(sep) -> sliceorstr.split(sep).rev()
* path.rev_components() -> path.components().rev()
* path.rev_str_components() -> path.str_components().rev()

In terms of the type system, this change also deprecates any specialized reversed iterator types (except
in treemap), opting instead to use Rev directly if any type annotations are needed. However, since
methods directly returning reversed iterators are now discouraged, the need for such annotations should
be small. However, in those cases, the general pattern for conversion is to take whatever follows Rev in
the original reversed name and surround it with Rev<>:

* RevComponents<'a> -> Rev<Components<'a>>
* RevStrComponents<'a> -> Rev<StrComponents<'a>>
* RevItems<'a, T> -> Rev<Items<'a, T>>
* etc.

The reasoning behind this change is that it makes the standard API much simpler without reducing readability,
performance, or power. The presence of functions such as rev_iter adds more boilerplate code to libraries
(all of which simply call .iter().rev()), clutters up the documentation, and only helps code by saving two
characters. Additionally, the numerous type synonyms that were used to make the type signatures look nice
like RevItems add even more boilerplate and clutter up the docs even more. With this change, all that cruft
goes away.

[breaking-change]
Diffstat (limited to 'src/libstd/path')
-rw-r--r--src/libstd/path/posix.rs22
-rw-r--r--src/libstd/path/windows.rs20
2 files changed, 25 insertions, 17 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs
index eceeb73a015..d69e9b448be 100644
--- a/src/libstd/path/posix.rs
+++ b/src/libstd/path/posix.rs
@@ -29,12 +29,14 @@ use super::{BytesContainer, GenericPath, GenericPathUnsafe};
 /// Iterator that yields successive components of a Path as &[u8]
 pub type Components<'a> = Splits<'a, u8>;
 /// Iterator that yields components of a Path in reverse as &[u8]
+#[deprecated = "replaced by Rev<Components<'a>>"]
 pub type RevComponents<'a> = Rev<Components<'a>>;
 
 /// Iterator that yields successive components of a Path as Option<&str>
 pub type StrComponents<'a> = Map<'a, &'a [u8], Option<&'a str>,
                                        Components<'a>>;
 /// Iterator that yields components of a Path in reverse as Option<&str>
+#[deprecated = "replaced by Rev<StrComponents<'a>>"]
 pub type RevStrComponents<'a> = Rev<StrComponents<'a>>;
 
 /// Represents a POSIX file path
@@ -307,8 +309,8 @@ impl GenericPath for Path {
 
     fn ends_with_path(&self, child: &Path) -> bool {
         if !child.is_relative() { return false; }
-        let mut selfit = self.rev_components();
-        let mut childit = child.rev_components();
+        let mut selfit = self.components().rev();
+        let mut childit = child.components().rev();
         loop {
             match (selfit.next(), childit.next()) {
                 (Some(a), Some(b)) => if a != b { return false; },
@@ -395,7 +397,8 @@ impl Path {
 
     /// Returns an iterator that yields each component of the path in reverse.
     /// See components() for details.
-    pub fn rev_components<'a>(&'a self) -> RevComponents<'a> {
+    #[deprecated = "replaced by .components().rev()"]
+    pub fn rev_components<'a>(&'a self) -> Rev<Components<'a>> {
         self.components().rev()
     }
 
@@ -407,7 +410,8 @@ impl Path {
 
     /// Returns an iterator that yields each component of the path in reverse as Option<&str>.
     /// See components() for details.
-    pub fn rev_str_components<'a>(&'a self) -> RevStrComponents<'a> {
+    #[deprecated = "replaced by .str_components().rev()"]
+    pub fn rev_str_components<'a>(&'a self) -> Rev<StrComponents<'a>> {
         self.str_components().rev()
     }
 }
@@ -1183,7 +1187,7 @@ mod tests {
                     let exps = exp.iter().map(|x| x.as_bytes()).collect::<Vec<&[u8]>>();
                     assert!(comps == exps, "components: Expected {:?}, found {:?}",
                             comps, exps);
-                    let comps = path.rev_components().collect::<Vec<&[u8]>>();
+                    let comps = path.components().rev().collect::<Vec<&[u8]>>();
                     let exps = exps.move_iter().rev().collect::<Vec<&[u8]>>();
                     assert!(comps == exps, "rev_components: Expected {:?}, found {:?}",
                             comps, exps);
@@ -1195,8 +1199,8 @@ mod tests {
                     let comps = path.components().collect::<Vec<&[u8]>>();
                     let exp: &[&[u8]] = [$(b!($($exp),*)),*];
                     assert_eq!(comps.as_slice(), exp);
-                    let comps = path.rev_components().collect::<Vec<&[u8]>>();
-                    let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&[u8]>>();
+                    let comps = path.components().rev().collect::<Vec<&[u8]>>();
+                    let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
                     assert_eq!(comps, exp)
                 }
             )
@@ -1227,8 +1231,8 @@ mod tests {
                     let comps = path.str_components().collect::<Vec<Option<&str>>>();
                     let exp: &[Option<&str>] = $exp;
                     assert_eq!(comps.as_slice(), exp);
-                    let comps = path.rev_str_components().collect::<Vec<Option<&str>>>();
-                    let exp = exp.rev_iter().map(|&x|x).collect::<Vec<Option<&str>>>();
+                    let comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
+                    let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
                     assert_eq!(comps, exp);
                 }
             )
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs
index 679075fe6ca..758a76167cd 100644
--- a/src/libstd/path/windows.rs
+++ b/src/libstd/path/windows.rs
@@ -37,12 +37,14 @@ pub type StrComponents<'a> = Map<'a, &'a str, Option<&'a str>,
 ///
 /// Each component is yielded as Option<&str> for compatibility with PosixPath, but
 /// every component in WindowsPath is guaranteed to be Some.
+#[deprecated = "replaced by Rev<StrComponents<'a>>"]
 pub type RevStrComponents<'a> = Rev<StrComponents<'a>>;
 
 /// Iterator that yields successive components of a Path as &[u8]
 pub type Components<'a> = Map<'a, Option<&'a str>, &'a [u8],
                                     StrComponents<'a>>;
 /// Iterator that yields components of a Path in reverse as &[u8]
+#[deprecated = "replaced by Rev<Components<'a>>"]
 pub type RevComponents<'a> = Rev<Components<'a>>;
 
 /// Represents a Windows path
@@ -631,7 +633,8 @@ impl Path {
 
     /// Returns an iterator that yields each component of the path in reverse as an Option<&str>
     /// See str_components() for details.
-    pub fn rev_str_components<'a>(&'a self) -> RevStrComponents<'a> {
+    #[deprecated = "replaced by .str_components().rev()"]
+    pub fn rev_str_components<'a>(&'a self) -> Rev<StrComponents<'a>> {
         self.str_components().rev()
     }
 
@@ -647,7 +650,8 @@ impl Path {
 
     /// Returns an iterator that yields each component of the path in reverse as a &[u8].
     /// See str_components() for details.
-    pub fn rev_components<'a>(&'a self) -> RevComponents<'a> {
+    #[deprecated = "replaced by .components().rev()"]
+    pub fn rev_components<'a>(&'a self) -> Rev<Components<'a>> {
         self.components().rev()
     }
 
@@ -2233,9 +2237,9 @@ mod tests {
                                 .collect::<Vec<&str>>();
                     let exp: &[&str] = $exp;
                     assert_eq!(comps.as_slice(), exp);
-                    let comps = path.rev_str_components().map(|x|x.unwrap())
+                    let comps = path.str_components().rev().map(|x|x.unwrap())
                                 .collect::<Vec<&str>>();
-                    let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&str>>();
+                    let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>();
                     assert_eq!(comps, exp);
                 }
             );
@@ -2245,9 +2249,9 @@ mod tests {
                     let comps = path.str_components().map(|x|x.unwrap()).collect::<Vec<&str>>();
                     let exp: &[&str] = $exp;
                     assert_eq!(comps.as_slice(), exp);
-                    let comps = path.rev_str_components().map(|x|x.unwrap())
+                    let comps = path.str_components().rev().map(|x|x.unwrap())
                                 .collect::<Vec<&str>>();
-                    let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&str>>();
+                    let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>();
                     assert_eq!(comps, exp);
                 }
             )
@@ -2302,8 +2306,8 @@ mod tests {
                     let comps = path.components().collect::<Vec<&[u8]>>();
                     let exp: &[&[u8]] = $exp;
                     assert_eq!(comps.as_slice(), exp);
-                    let comps = path.rev_components().collect::<Vec<&[u8]>>();
-                    let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&[u8]>>();
+                    let comps = path.components().rev().collect::<Vec<&[u8]>>();
+                    let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
                     assert_eq!(comps, exp);
                 }
             )