diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 5847a6177d729..4857155440e1d 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -86,6 +86,13 @@ pub trait ImmutableSlice<'a, T> { #[unstable = "waiting on final error conventions/slicing syntax"] fn slice_to(&self, end: uint) -> &'a [T]; + /// Returns a subslice spanning the interval [`start`, `start + len`). + /// + /// Fails when the end of the new slice lies beyond the end of the + /// original slice (i.e. when `start + len > self.len()`). + #[experimental] + fn slice_at(&self, start: uint, len: uint) -> &'a [T]; + /// Divides one slice into two at an index. /// /// The first will contain all indices from `[0, mid)` (excluding @@ -315,6 +322,11 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { self.slice(0, end) } + #[inline] + fn slice_at(&self, start: uint, len: uint) -> &'a [T] { + self.slice(start, start + len) + } + #[inline] fn split_at(&self, mid: uint) -> (&'a [T], &'a [T]) { ((*self)[..mid], (*self)[mid..]) @@ -606,6 +618,13 @@ pub trait MutableSlice<'a, T> { self.iter_mut() } + /// Returns a mutable subslice spanning the interval [`start`, `start + len`). + /// + /// Fails when the end of the new slice lies beyond the end of the + /// original slice (i.e. when `start + len > self.len()`). + #[experimental] + fn slice_at_mut(self, start: uint, len: uint) -> &'a mut [T]; + /// Returns an iterator that allows modifying each value #[unstable = "waiting on iterator type name conventions"] fn iter_mut(self) -> MutItems<'a, T>; @@ -841,6 +860,11 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { self[mut ..end] } + #[inline] + fn slice_at_mut(self, start: uint, len: uint) -> &'a mut [T] { + self[mut start..(start + len)] + } + #[inline] fn split_at_mut(self, mid: uint) -> (&'a mut [T], &'a mut [T]) { unsafe {