Skip to content

Commit d7c9bb4

Browse files
committed
vec: add mut_slice_{to,from}
Closes #8066
1 parent d6bc438 commit d7c9bb4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libstd/vec.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,8 @@ impl<T:Eq> OwnedEqVector<T> for ~[T] {
16561656
#[allow(missing_doc)]
16571657
pub trait MutableVector<'self, T> {
16581658
fn mut_slice(self, start: uint, end: uint) -> &'self mut [T];
1659+
fn mut_slice_from(self, start: uint) -> &'self mut [T];
1660+
fn mut_slice_to(self, end: uint) -> &'self mut [T];
16591661
fn mut_iter(self) -> VecMutIterator<'self, T>;
16601662
fn mut_rev_iter(self) -> VecMutRevIterator<'self, T>;
16611663

@@ -1709,6 +1711,27 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
17091711
}
17101712
}
17111713

1714+
/**
1715+
* Returns a slice of self from `start` to the end of the vec.
1716+
*
1717+
* Fails when `start` points outside the bounds of self.
1718+
*/
1719+
#[inline]
1720+
fn mut_slice_from(self, start: uint) -> &'self mut [T] {
1721+
let len = self.len();
1722+
self.mut_slice(start, len)
1723+
}
1724+
1725+
/**
1726+
* Returns a slice of self from the start of the vec to `end`.
1727+
*
1728+
* Fails when `end` points outside the bounds of self.
1729+
*/
1730+
#[inline]
1731+
fn mut_slice_to(self, end: uint) -> &'self mut [T] {
1732+
self.mut_slice(0, end)
1733+
}
1734+
17121735
#[inline]
17131736
fn mut_split(self, mid: uint) -> (&'self mut [T], &'self mut [T]) {
17141737
unsafe {

0 commit comments

Comments
 (0)