diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2014-10-05 11:59:10 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2014-10-07 15:49:53 +1300 |
| commit | 3b0550c3a94baa8ed4a5c25fc69a2859acb65673 (patch) | |
| tree | d83c0326466a5fb14163ef970951f72e9ea80b64 /src/libcollections | |
| parent | cd21e4a72c0175d226acc837d1886cfdfa40fe68 (diff) | |
| download | rust-3b0550c3a94baa8ed4a5c25fc69a2859acb65673.tar.gz rust-3b0550c3a94baa8ed4a5c25fc69a2859acb65673.zip | |
Rename slicing methods
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/string.rs | 23 | ||||
| -rw-r--r-- | src/libcollections/trie.rs | 18 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 46 |
3 files changed, 86 insertions, 1 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 19edc1d2b00..0a460b64210 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -928,6 +928,7 @@ impl<S: Str> Add<S, String> for String { } } +#[cfg(stage0)] impl ops::Slice<uint, str> for String { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { @@ -949,6 +950,28 @@ impl ops::Slice<uint, str> for String { self[][*from..*to] } } +#[cfg(not(stage0))] +impl ops::Slice<uint, str> for String { + #[inline] + fn as_slice_<'a>(&'a self) -> &'a str { + self.as_slice() + } + + #[inline] + fn slice_from_or_fail<'a>(&'a self, from: &uint) -> &'a str { + self[][*from..] + } + + #[inline] + fn slice_to_or_fail<'a>(&'a self, to: &uint) -> &'a str { + self[][..*to] + } + + #[inline] + fn slice_or_fail<'a>(&'a self, from: &uint, to: &uint) -> &'a str { + self[][*from..*to] + } +} /// Unsafe operations #[unstable = "waiting on raw module conventions"] diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 04175173feb..66f41d2ba1f 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -389,6 +389,7 @@ macro_rules! bound { impl<T> TrieMap<T> { // If `upper` is true then returns upper_bound else returns lower_bound. + #[cfg(stage0)] #[inline] fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> { bound!(Entries, self = self, @@ -396,6 +397,14 @@ impl<T> TrieMap<T> { slice_from = slice_from_, iter = iter, mutability = ) } + #[cfg(not(stage0))] + #[inline] + fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> { + bound!(Entries, self = self, + key = key, is_upper = upper, + slice_from = slice_from_or_fail, iter = iter, + mutability = ) + } /// Gets an iterator pointing to the first key-value pair whose key is not less than `key`. /// If all keys in the map are less than `key` an empty iterator is returned. @@ -431,6 +440,7 @@ impl<T> TrieMap<T> { self.bound(key, true) } // If `upper` is true then returns upper_bound else returns lower_bound. + #[cfg(stage0)] #[inline] fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> { bound!(MutEntries, self = self, @@ -438,6 +448,14 @@ impl<T> TrieMap<T> { slice_from = slice_from_mut_, iter = iter_mut, mutability = mut) } + #[cfg(not(stage0))] + #[inline] + fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> { + bound!(MutEntries, self = self, + key = key, is_upper = upper, + slice_from = slice_from_or_fail_mut, iter = iter_mut, + mutability = mut) + } /// Deprecated: use `lower_bound_mut`. #[deprecated = "use lower_bound_mut"] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index b995af952f1..da88b5efa61 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -460,6 +460,7 @@ impl<T> Index<uint,T> for Vec<T> { } }*/ +#[cfg(stage0)] impl<T> ops::Slice<uint, [T]> for Vec<T> { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { @@ -480,7 +481,29 @@ impl<T> ops::Slice<uint, [T]> for Vec<T> { self.as_slice().slice_(start, end) } } +#[cfg(not(stage0))] +impl<T> ops::Slice<uint, [T]> for Vec<T> { + #[inline] + fn as_slice_<'a>(&'a self) -> &'a [T] { + self.as_slice() + } + + #[inline] + fn slice_from_or_fail<'a>(&'a self, start: &uint) -> &'a [T] { + self.as_slice().slice_from_or_fail(start) + } + #[inline] + fn slice_to_or_fail<'a>(&'a self, end: &uint) -> &'a [T] { + self.as_slice().slice_to_or_fail(end) + } + #[inline] + fn slice_or_fail<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] { + self.as_slice().slice_or_fail(start, end) + } +} + +#[cfg(stage0)] impl<T> ops::SliceMut<uint, [T]> for Vec<T> { #[inline] fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { @@ -501,6 +524,27 @@ impl<T> ops::SliceMut<uint, [T]> for Vec<T> { self.as_mut_slice().slice_mut_(start, end) } } +#[cfg(not(stage0))] +impl<T> ops::SliceMut<uint, [T]> for Vec<T> { + #[inline] + fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] { + self.as_mut_slice() + } + + #[inline] + fn slice_from_or_fail_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] { + self.as_mut_slice().slice_from_or_fail_mut(start) + } + + #[inline] + fn slice_to_or_fail_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] { + self.as_mut_slice().slice_to_or_fail_mut(end) + } + #[inline] + fn slice_or_fail_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] { + self.as_mut_slice().slice_or_fail_mut(start, end) + } +} #[experimental = "waiting on FromIterator stability"] impl<T> FromIterator<T> for Vec<T> { @@ -1181,7 +1225,7 @@ impl<T> Vec<T> { } /// Deprecated: use `slice_mut`. - #[deprecated = "use slice_from"] + #[deprecated = "use slice_mut"] pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] { self[mut start..end] |
