diff options
| author | bors <bors@rust-lang.org> | 2014-04-30 15:46:47 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-30 15:46:47 -0700 |
| commit | 9f484e616e8731c3fd9346460a71156ddba454b4 (patch) | |
| tree | 040aacc920be7044251435cb3883e4f7a1166aa6 /src/libstd/path | |
| parent | 3aadbed612fd877488b11347d83bfd8f6dc08fe6 (diff) | |
| parent | 03609e5a5e8bdca9452327d44e25407ce888d0bb (diff) | |
| download | rust-9f484e616e8731c3fd9346460a71156ddba454b4.tar.gz rust-9f484e616e8731c3fd9346460a71156ddba454b4.zip | |
auto merge of #13648 : gereeter/rust/removed-rev, r=alexcrichton
In the process, `Splits` got changed to be more like `CharSplits` in `str` to present the DEI interface. Note that `treemap` still has a `rev_iter` function because it seems like it would be a significant interface change to expose a DEI - the iterator would have to gain an extra pointer, the completion checks would be more complicated, and it isn't easy to check that such an implementation is correct due to the use of unsafety to subvert the aliasing properties of `&mut`. This fixes #9391.
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/posix.rs | 45 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 34 |
2 files changed, 36 insertions, 43 deletions
diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 4affea37e35..d69e9b448be 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -16,11 +16,11 @@ use clone::Clone; use cmp::{Eq, TotalEq}; use from_str::FromStr; use io::Writer; -use iter::{AdditiveIterator, Extendable, Iterator, Map}; +use iter::{DoubleEndedIterator, Rev, AdditiveIterator, Extendable, Iterator, Map}; use option::{Option, None, Some}; use str; use str::Str; -use slice::{CloneableVector, RevSplits, Splits, Vector, VectorVector, +use slice::{CloneableVector, Splits, Vector, VectorVector, ImmutableEqVector, OwnedVector, ImmutableVector}; use vec::Vec; @@ -29,14 +29,15 @@ 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] -pub type RevComponents<'a> = RevSplits<'a, 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> -pub type RevStrComponents<'a> = Map<'a, &'a [u8], Option<&'a str>, - RevComponents<'a>>; +#[deprecated = "replaced by Rev<StrComponents<'a>>"] +pub type RevStrComponents<'a> = Rev<StrComponents<'a>>; /// Represents a POSIX file path #[deriving(Clone)] @@ -308,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; }, @@ -396,16 +397,9 @@ 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> { - let v = if *self.repr.get(0) == SEP_BYTE { - self.repr.slice_from(1) - } else { self.repr.as_slice() }; - let mut ret = v.rsplit(is_sep_byte); - if v.is_empty() { - // consume the empty "" component - ret.next(); - } - ret + #[deprecated = "replaced by .components().rev()"] + pub fn rev_components<'a>(&'a self) -> Rev<Components<'a>> { + self.components().rev() } /// Returns an iterator that yields each component of the path as Option<&str>. @@ -416,8 +410,9 @@ 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> { - self.rev_components().map(str::from_utf8) + #[deprecated = "replaced by .str_components().rev()"] + pub fn rev_str_components<'a>(&'a self) -> Rev<StrComponents<'a>> { + self.str_components().rev() } } @@ -1192,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); @@ -1204,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) } ) @@ -1236,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 74ca8dc5785..758a76167cd 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -37,15 +37,15 @@ 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. -pub type RevStrComponents<'a> = Rev<Map<'a, &'a str, Option<&'a str>, - CharSplits<'a, char>>>; +#[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] -pub type RevComponents<'a> = Map<'a, Option<&'a str>, &'a [u8], - RevStrComponents<'a>>; +#[deprecated = "replaced by Rev<Components<'a>>"] +pub type RevComponents<'a> = Rev<Components<'a>>; /// Represents a Windows path // Notes for Windows path impl: @@ -633,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() } @@ -649,12 +650,9 @@ 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> { - fn convert<'a>(x: Option<&'a str>) -> &'a [u8] { - #![inline] - x.unwrap().as_bytes() - } - self.rev_str_components().map(convert) + #[deprecated = "replaced by .components().rev()"] + pub fn rev_components<'a>(&'a self) -> Rev<Components<'a>> { + self.components().rev() } fn equiv_prefix(&self, other: &Path) -> bool { @@ -2239,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); } ); @@ -2251,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); } ) @@ -2308,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); } ) |
