Skip to content

Commit 092ba6a

Browse files
committed
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]
1 parent fba0bf6 commit 092ba6a

File tree

5 files changed

+115
-185
lines changed

5 files changed

+115
-185
lines changed

src/libcollections/slice.rs

+18-44
Original file line numberDiff line numberDiff line change
@@ -169,29 +169,16 @@ pub trait SliceExt {
169169
#[unstable = "uncertain about this API approach"]
170170
fn move_from(&mut self, src: Vec<Self::Item>, start: uint, end: uint) -> uint;
171171

172-
/// Returns a subslice spanning the interval [`start`, `end`).
173-
///
174-
/// Panics when the end of the new slice lies beyond the end of the
175-
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
176-
///
177-
/// Slicing with `start` equal to `end` yields an empty slice.
178-
#[unstable = "will be replaced by slice syntax"]
172+
/// Deprecated: use `&s[start .. end]` notation instead.
173+
#[deprecated = "use &s[start .. end] instead"]
179174
fn slice(&self, start: uint, end: uint) -> &[Self::Item];
180175

181-
/// Returns a subslice from `start` to the end of the slice.
182-
///
183-
/// Panics when `start` is strictly greater than the length of the original slice.
184-
///
185-
/// Slicing from `self.len()` yields an empty slice.
186-
#[unstable = "will be replaced by slice syntax"]
176+
/// Deprecated: use `&s[start..]` notation instead.
177+
#[deprecated = "use &s[start..] isntead"]
187178
fn slice_from(&self, start: uint) -> &[Self::Item];
188179

189-
/// Returns a subslice from the start of the slice to `end`.
190-
///
191-
/// Panics when `end` is strictly greater than the length of the original slice.
192-
///
193-
/// Slicing to `0` yields an empty slice.
194-
#[unstable = "will be replaced by slice syntax"]
180+
/// Deprecated: use `&s[..end]` notation instead.
181+
#[deprecated = "use &s[..end] instead"]
195182
fn slice_to(&self, end: uint) -> &[Self::Item];
196183

197184
/// Divides one slice into two at an index.
@@ -378,29 +365,16 @@ pub trait SliceExt {
378365
#[stable]
379366
fn as_mut_slice(&mut self) -> &mut [Self::Item];
380367

381-
/// Returns a mutable subslice spanning the interval [`start`, `end`).
382-
///
383-
/// Panics when the end of the new slice lies beyond the end of the
384-
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
385-
///
386-
/// Slicing with `start` equal to `end` yields an empty slice.
387-
#[unstable = "will be replaced by slice syntax"]
368+
/// Deprecated: use `&mut s[start .. end]` instead.
369+
#[deprecated = "use &mut s[start .. end] instead"]
388370
fn slice_mut(&mut self, start: uint, end: uint) -> &mut [Self::Item];
389371

390-
/// Returns a mutable subslice from `start` to the end of the slice.
391-
///
392-
/// Panics when `start` is strictly greater than the length of the original slice.
393-
///
394-
/// Slicing from `self.len()` yields an empty slice.
395-
#[unstable = "will be replaced by slice syntax"]
372+
/// Deprecated: use `&mut s[start ..]` instead.
373+
#[deprecated = "use &mut s[start ..] instead"]
396374
fn slice_from_mut(&mut self, start: uint) -> &mut [Self::Item];
397375

398-
/// Returns a mutable subslice from the start of the slice to `end`.
399-
///
400-
/// Panics when `end` is strictly greater than the length of the original slice.
401-
///
402-
/// Slicing to `0` yields an empty slice.
403-
#[unstable = "will be replaced by slice syntax"]
376+
/// Deprecated: use `&mut s[.. end]` instead.
377+
#[deprecated = "use &mut s[.. end] instead"]
404378
fn slice_to_mut(&mut self, end: uint) -> &mut [Self::Item];
405379

406380
/// Returns an iterator that allows modifying each value
@@ -720,17 +694,17 @@ impl<T> SliceExt for [T] {
720694

721695
#[inline]
722696
fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
723-
core_slice::SliceExt::slice(self, start, end)
697+
&self[start .. end]
724698
}
725699

726700
#[inline]
727701
fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
728-
core_slice::SliceExt::slice_from(self, start)
702+
&self[start ..]
729703
}
730704

731705
#[inline]
732706
fn slice_to<'a>(&'a self, end: uint) -> &'a [T] {
733-
core_slice::SliceExt::slice_to(self, end)
707+
&self[.. end]
734708
}
735709

736710
#[inline]
@@ -834,17 +808,17 @@ impl<T> SliceExt for [T] {
834808

835809
#[inline]
836810
fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T] {
837-
core_slice::SliceExt::slice_mut(self, start, end)
811+
&mut self[start .. end]
838812
}
839813

840814
#[inline]
841815
fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T] {
842-
core_slice::SliceExt::slice_from_mut(self, start)
816+
&mut self[start ..]
843817
}
844818

845819
#[inline]
846820
fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T] {
847-
core_slice::SliceExt::slice_to_mut(self, end)
821+
&mut self[.. end]
848822
}
849823

850824
#[inline]

src/libcollections/str.rs

+6-50
Original file line numberDiff line numberDiff line change
@@ -750,64 +750,20 @@ pub trait StrExt: Index<FullRange, Output = str> {
750750
core_str::StrExt::lines_any(&self[])
751751
}
752752

753-
/// Returns a slice of the given string from the byte range
754-
/// [`begin`..`end`).
755-
///
756-
/// This operation is `O(1)`.
757-
///
758-
/// Panics when `begin` and `end` do not point to valid characters
759-
/// or point beyond the last character of the string.
760-
///
761-
/// See also `slice_to` and `slice_from` for slicing prefixes and
762-
/// suffixes of strings, and `slice_chars` for slicing based on
763-
/// code point counts.
764-
///
765-
/// # Example
766-
///
767-
/// ```rust
768-
/// let s = "Löwe 老虎 Léopard";
769-
/// assert_eq!(s.slice(0, 1), "L");
770-
///
771-
/// assert_eq!(s.slice(1, 9), "öwe 老");
772-
///
773-
/// // these will panic:
774-
/// // byte 2 lies within `ö`:
775-
/// // s.slice(2, 3);
776-
///
777-
/// // byte 8 lies within `老`
778-
/// // s.slice(1, 8);
779-
///
780-
/// // byte 100 is outside the string
781-
/// // s.slice(3, 100);
782-
/// ```
783-
#[unstable = "use slice notation [a..b] instead"]
753+
/// Deprecated: use `s[a .. b]` instead.
754+
#[deprecated = "use slice notation [a..b] instead"]
784755
fn slice(&self, begin: uint, end: uint) -> &str {
785756
core_str::StrExt::slice(&self[], begin, end)
786757
}
787758

788-
/// Returns a slice of the string from `begin` to its end.
789-
///
790-
/// Equivalent to `self.slice(begin, self.len())`.
791-
///
792-
/// Panics when `begin` does not point to a valid character, or is
793-
/// out of bounds.
794-
///
795-
/// See also `slice`, `slice_to` and `slice_chars`.
796-
#[unstable = "use slice notation [a..] instead"]
759+
/// Deprecated: use `s[a..]` instead.
760+
#[deprecated = "use slice notation [a..] instead"]
797761
fn slice_from(&self, begin: uint) -> &str {
798762
core_str::StrExt::slice_from(&self[], begin)
799763
}
800764

801-
/// Returns a slice of the string from the beginning to byte
802-
/// `end`.
803-
///
804-
/// Equivalent to `self.slice(0, end)`.
805-
///
806-
/// Panics when `end` does not point to a valid character, or is
807-
/// out of bounds.
808-
///
809-
/// See also `slice`, `slice_from` and `slice_chars`.
810-
#[unstable = "use slice notation [..a] instead"]
765+
/// Deprecated: use `s[..a]` instead.
766+
#[deprecated = "use slice notation [..a] instead"]
811767
fn slice_to(&self, end: uint) -> &str {
812768
core_str::StrExt::slice_to(&self[], end)
813769
}

src/libcollections/string.rs

+4
Original file line numberDiff line numberDiff line change
@@ -848,27 +848,31 @@ impl<'a> Add<&'a str> for String {
848848
}
849849
}
850850

851+
#[stable]
851852
impl ops::Index<ops::Range<uint>> for String {
852853
type Output = str;
853854
#[inline]
854855
fn index(&self, index: &ops::Range<uint>) -> &str {
855856
&self[][*index]
856857
}
857858
}
859+
#[stable]
858860
impl ops::Index<ops::RangeTo<uint>> for String {
859861
type Output = str;
860862
#[inline]
861863
fn index(&self, index: &ops::RangeTo<uint>) -> &str {
862864
&self[][*index]
863865
}
864866
}
867+
#[stable]
865868
impl ops::Index<ops::RangeFrom<uint>> for String {
866869
type Output = str;
867870
#[inline]
868871
fn index(&self, index: &ops::RangeFrom<uint>) -> &str {
869872
&self[][*index]
870873
}
871874
}
875+
#[stable]
872876
impl ops::Index<ops::FullRange> for String {
873877
type Output = str;
874878
#[inline]

0 commit comments

Comments
 (0)