diff options
| author | Jonathan S <gereeter@gmail.com> | 2014-04-20 21:28:38 -0500 |
|---|---|---|
| committer | Jonathan S <gereeter@gmail.com> | 2014-04-28 16:45:36 -0500 |
| commit | f58a8c9d760aead49e138fa8045e229a47217644 (patch) | |
| tree | 38becfafd8f09f0da6bb227b4024894f3d6d7584 /src/libstd/path/windows.rs | |
| parent | 23262a83909392f88fdc8031ebd754f8d9b94525 (diff) | |
| download | rust-f58a8c9d760aead49e138fa8045e229a47217644.tar.gz rust-f58a8c9d760aead49e138fa8045e229a47217644.zip | |
Provide an implementation of DoubleEndedIterator for the results of &[T]::split and &[T]::rsplit
This makes the splitting functions in std::slice return DoubleEndedIterators. Unfortunately, splitn and rsplitn cannot provide such an interface and so must return different types. As a result, the following changes were made: * RevSplits was removed in favor of explicitly using Rev * Splits can no longer bound the number of splits done * Splits now implements DoubleEndedIterator * SplitsN was added, taking the role of what both Splits and RevSplits used to be * rsplit returns Rev<Splits<'a, T>> instead of RevSplits<'a, T> * splitn returns SplitsN<'a, T> instead of Splits<'a, T> * rsplitn returns SplitsN<'a, T> instead of RevSplits<'a, T> All functions that were previously implemented on each return value still are, so outside of changing of type annotations, existing code should work out of the box. In the rare case that code relied on the return types of split and splitn or of rsplit and rsplitn being the same, the previous behavior can be emulated by calling splitn or rsplitn with a bount of uint::MAX. The value of this change comes in multiple parts: * Consistency. The splitting code in std::str is structured similarly to the new slice splitting code, having separate CharSplits and CharSplitsN types. * Smaller API. Although this commit doesn't implement it, using a DoubleEndedIterator for splitting means that rsplit, path::RevComponents, path::RevStrComponents, Path::rev_components, and Path::rev_str_components are no longer needed - they can be emulated simply with .rev(). * Power. DoubleEndedIterators are able to traverse the list from both sides at once instead of only forwards or backwards. * Efficiency. For the common case of using split instead of splitn, the iterator is slightly smaller and slightly faster. [breaking-change]
Diffstat (limited to 'src/libstd/path/windows.rs')
| -rw-r--r-- | src/libstd/path/windows.rs | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 74ca8dc5785..679075fe6ca 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,13 @@ 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>>>; +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>>; +pub type RevComponents<'a> = Rev<Components<'a>>; /// Represents a Windows path // Notes for Windows path impl: @@ -650,11 +648,7 @@ 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) + self.components().rev() } fn equiv_prefix(&self, other: &Path) -> bool { |
