diff options
| author | Aaron Turon <aturon@mozilla.com> | 2015-01-17 16:15:47 -0800 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2015-01-21 07:45:45 -0800 |
| commit | 092ba6a8563b5c95f5aa53a705eaba6cc94e2da7 (patch) | |
| tree | 17deb06bc801ba7201beeaa337716fbae6279195 /src/libcollections | |
| parent | fba0bf63a90379e8825012a817167774e14a627f (diff) | |
Deprecate slicing methods in favor of notation
This commit deprecates `slice`, `slice_from`, `slice_to` and their mutable variants in favor of slice notation. The `as_slice` methods are left intact, for now. [breaking-change]
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/slice.rs | 62 | ||||
| -rw-r--r-- | src/libcollections/str.rs | 56 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 4 |
3 files changed, 28 insertions, 94 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 988ec4c661f..a640e4ee0e3 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -169,29 +169,16 @@ pub trait SliceExt { #[unstable = "uncertain about this API approach"] fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint; - /// Returns a subslice spanning the interval [`start`, `end`). - /// - /// Panics when the end of the new slice lies beyond the end of the - /// original slice (i.e. when `end > self.len()`) or when `start > end`. - /// - /// Slicing with `start` equal to `end` yields an empty slice. - #[unstable = "will be replaced by slice syntax"] + /// Deprecated: use `&s[start .. end]` notation instead. + #[deprecated = "use &s[start .. end] instead"] fn slice(&self, start: uint, end: uint) -> &[Self::Item]; - /// Returns a subslice from `start` to the end of the slice. - /// - /// Panics when `start` is strictly greater than the length of the original slice. - /// - /// Slicing from `self.len()` yields an empty slice. - #[unstable = "will be replaced by slice syntax"] + /// Deprecated: use `&s[start..]` notation instead. + #[deprecated = "use &s[start..] isntead"] fn slice_from(&self, start: uint) -> &[Self::Item]; - /// Returns a subslice from the start of the slice to `end`. - /// - /// Panics when `end` is strictly greater than the length of the original slice. - /// - /// Slicing to `0` yields an empty slice. - #[unstable = "will be replaced by slice syntax"] + /// Deprecated: use `&s[..end]` notation instead. + #[deprecated = "use &s[..end] instead"] fn slice_to(&self, end: uint) -> &[Self::Item]; /// Divides one slice into two at an index. @@ -378,29 +365,16 @@ pub trait SliceExt { #[stable] fn as_mut_slice(&mut self) -> &mut [Self::Item]; - /// Returns a mutable subslice spanning the interval [`start`, `end`). - /// - /// Panics when the end of the new slice lies beyond the end of the - /// original slice (i.e. when `end > self.len()`) or when `start > end`. - /// - /// Slicing with `start` equal to `end` yields an empty slice. - #[unstable = "will be replaced by slice syntax"] + /// Deprecated: use `&mut s[start .. end]` instead. + #[deprecated = "use &mut s[start .. end] instead"] fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item]; - /// Returns a mutable subslice from `start` to the end of the slice. - /// - /// Panics when `start` is strictly greater than the length of the original slice. - /// - /// Slicing from `self.len()` yields an empty slice. - #[unstable = "will be replaced by slice syntax"] + /// Deprecated: use `&mut s[start ..]` instead. + #[deprecated = "use &mut s[start ..] instead"] fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item]; - /// Returns a mutable subslice from the start of the slice to `end`. - /// - /// Panics when `end` is strictly greater than the length of the original slice. - /// - /// Slicing to `0` yields an empty slice. - #[unstable = "will be replaced by slice syntax"] + /// Deprecated: use `&mut s[.. end]` instead. + #[deprecated = "use &mut s[.. end] instead"] fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item]; /// Returns an iterator that allows modifying each value @@ -720,17 +694,17 @@ impl<T> SliceExt for [T] { #[inline] fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] { - core_slice::SliceExt::slice(self, start, end) + &self[start .. end] } #[inline] fn slice_from<'a>(&'a self, start: uint) -> &'a [T] { - core_slice::SliceExt::slice_from(self, start) + &self[start ..] } #[inline] fn slice_to<'a>(&'a self, end: uint) -> &'a [T] { - core_slice::SliceExt::slice_to(self, end) + &self[.. end] } #[inline] @@ -834,17 +808,17 @@ impl<T> SliceExt for [T] { #[inline] fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] { - core_slice::SliceExt::slice_mut(self, start, end) + &mut self[start .. end] } #[inline] fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] { - core_slice::SliceExt::slice_from_mut(self, start) + &mut self[start ..] } #[inline] fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] { - core_slice::SliceExt::slice_to_mut(self, end) + &mut self[.. end] } #[inline] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index f7668930660..94554fd1e81 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -750,64 +750,20 @@ pub trait StrExt: Index<FullRange, Output = str> { core_str::StrExt::lines_any(&self[]) } - /// Returns a slice of the given string from the byte range - /// [`begin`..`end`). - /// - /// This operation is `O(1)`. - /// - /// Panics when `begin` and `end` do not point to valid characters - /// or point beyond the last character of the string. - /// - /// See also `slice_to` and `slice_from` for slicing prefixes and - /// suffixes of strings, and `slice_chars` for slicing based on - /// code point counts. - /// - /// # Example - /// - /// ```rust - /// let s = "Löwe 老虎 Léopard"; - /// assert_eq!(s.slice(0, 1), "L"); - /// - /// assert_eq!(s.slice(1, 9), "öwe 老"); - /// - /// // these will panic: - /// // byte 2 lies within `ö`: - /// // s.slice(2, 3); - /// - /// // byte 8 lies within `老` - /// // s.slice(1, 8); - /// - /// // byte 100 is outside the string - /// // s.slice(3, 100); - /// ``` - #[unstable = "use slice notation [a..b] instead"] + /// Deprecated: use `s[a .. b]` instead. + #[deprecated = "use slice notation [a..b] instead"] fn slice(&self, begin: uint, end: uint) -> &str { core_str::StrExt::slice(&self[], begin, end) } - /// Returns a slice of the string from `begin` to its end. - /// - /// Equivalent to `self.slice(begin, self.len())`. - /// - /// Panics when `begin` does not point to a valid character, or is - /// out of bounds. - /// - /// See also `slice`, `slice_to` and `slice_chars`. - #[unstable = "use slice notation [a..] instead"] + /// Deprecated: use `s[a..]` instead. + #[deprecated = "use slice notation [a..] instead"] fn slice_from(&self, begin: uint) -> &str { core_str::StrExt::slice_from(&self[], begin) } - /// Returns a slice of the string from the beginning to byte - /// `end`. - /// - /// Equivalent to `self.slice(0, end)`. - /// - /// Panics when `end` does not point to a valid character, or is - /// out of bounds. - /// - /// See also `slice`, `slice_from` and `slice_chars`. - #[unstable = "use slice notation [..a] instead"] + /// Deprecated: use `s[..a]` instead. + #[deprecated = "use slice notation [..a] instead"] fn slice_to(&self, end: uint) -> &str { core_str::StrExt::slice_to(&self[], end) } diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 5d35d8a8679..4a73757baf9 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -848,6 +848,7 @@ impl<'a> Add<&'a str> for String { } } +#[stable] impl ops::Index<ops::Range<uint>> for String { type Output = str; #[inline] @@ -855,6 +856,7 @@ impl ops::Index<ops::Range<uint>> for String { &self[][*index] } } +#[stable] impl ops::Index<ops::RangeTo<uint>> for String { type Output = str; #[inline] @@ -862,6 +864,7 @@ impl ops::Index<ops::RangeTo<uint>> for String { &self[][*index] } } +#[stable] impl ops::Index<ops::RangeFrom<uint>> for String { type Output = str; #[inline] @@ -869,6 +872,7 @@ impl ops::Index<ops::RangeFrom<uint>> for String { &self[][*index] } } +#[stable] impl ops::Index<ops::FullRange> for String { type Output = str; #[inline] |
