Skip to content

Commit 01209f1

Browse files
committed
Add method .as_mut_slice() to MutableVector
This method is primarily intended to allow for converting a [T, ..N] to a &mut [T].
1 parent aa5d779 commit 01209f1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libstd/vec.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,10 @@ fn merge_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
20692069
/// Extension methods for vectors such that their elements are
20702070
/// mutable.
20712071
pub trait MutableVector<'a, T> {
2072+
/// Work with `self` as a mut slice.
2073+
/// Primarily intended for getting a &mut [T] from a [T, ..N].
2074+
fn as_mut_slice(self) -> &'a mut [T];
2075+
20722076
/// Return a slice that points into another slice.
20732077
fn mut_slice(self, start: uint, end: uint) -> &'a mut [T];
20742078

@@ -2302,6 +2306,8 @@ pub trait MutableVector<'a, T> {
23022306

23032307
impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
23042308
#[inline]
2309+
fn as_mut_slice(self) -> &'a mut [T] { self }
2310+
23052311
fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
23062312
assert!(start <= end);
23072313
assert!(end <= self.len());

0 commit comments

Comments
 (0)