summary refs log tree commit diff
path: root/src/libcore/vec.rs
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-03-13 20:55:42 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-03-13 21:29:48 -0400
commitc64a5d2d37a91e2151da41324a7f5dfc2b9c05d3 (patch)
tree8b01e982656fe6477b10dbfe44f658f36e259646 /src/libcore/vec.rs
parentab5472a7244896df20ceb7a12d9d30afc838f004 (diff)
add a trait for mutable iterators
Diffstat (limited to 'src/libcore/vec.rs')
-rw-r--r--src/libcore/vec.rs31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 68dca608a48..b513f91cde9 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1358,7 +1358,7 @@ pub pure fn each<T>(v: &r/[T], f: &fn(&r/T) -> bool) {
 /// a vector with mutable contents and you would like
 /// to mutate the contents as you iterate.
 #[inline(always)]
-pub fn each_mut<T>(v: &mut [T], f: &fn(elem: &mut T) -> bool) {
+pub fn each_mut<T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) {
     let mut i = 0;
     let n = v.len();
     while i < n {
@@ -2282,11 +2282,9 @@ pub mod bytes {
 // ___________________________________________________________________________
 // ITERATION TRAIT METHODS
 
-impl<A> iter::BaseIter<A> for &self/[A] {
+impl<A> iter::BaseIter<A> for &'self [A] {
     #[inline(always)]
-    pub pure fn each(&self, blk: &fn(v: &'self A) -> bool) {
-        each(*self, blk)
-    }
+    pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) }
     #[inline(always)]
     pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
 }
@@ -2307,6 +2305,29 @@ impl<A> iter::BaseIter<A> for @[A] {
     pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
 }
 
+impl<A> iter::MutableIter<A> for &'self mut [A] {
+    #[inline(always)]
+    fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
+        each_mut(*self, blk)
+    }
+}
+
+// FIXME(#4148): This should be redundant
+impl<A> iter::MutableIter<A> for ~[A] {
+    #[inline(always)]
+    fn each_mut(&mut self, blk: &fn(v: &'self mut A) -> bool) {
+        each_mut(*self, blk)
+    }
+}
+
+// FIXME(#4148): This should be redundant
+impl<A> iter::MutableIter<A> for @mut [A] {
+    #[inline(always)]
+    fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) {
+        each_mut(*self, blk)
+    }
+}
+
 impl<A> iter::ExtendedIter<A> for &self/[A] {
     pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
         iter::eachi(self, blk)