From 01209f1e3aed4cd0960fe81dd1d1470650ae8b85 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 9 Dec 2013 14:45:53 -0800 Subject: [PATCH] Add method .as_mut_slice() to MutableVector This method is primarily intended to allow for converting a [T, ..N] to a &mut [T]. --- src/libstd/vec.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 9662a610810..450cf1a4ef2 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2069,6 +2069,10 @@ fn merge_sort(v: &mut [T], compare: |&T, &T| -> Ordering) { /// Extension methods for vectors such that their elements are /// mutable. pub trait MutableVector<'a, T> { + /// Work with `self` as a mut slice. + /// Primarily intended for getting a &mut [T] from a [T, ..N]. + fn as_mut_slice(self) -> &'a mut [T]; + /// Return a slice that points into another slice. fn mut_slice(self, start: uint, end: uint) -> &'a mut [T]; @@ -2302,6 +2306,8 @@ pub trait MutableVector<'a, T> { impl<'a,T> MutableVector<'a, T> for &'a mut [T] { #[inline] + fn as_mut_slice(self) -> &'a mut [T] { self } + fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] { assert!(start <= end); assert!(end <= self.len());