about summary refs log tree commit diff
path: root/src/libcore/vec.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-03-14 19:06:47 -0700
committerbors <bors@rust-lang.org>2013-03-14 19:06:47 -0700
commitc3fe0b97de67e0449aa20cd8ef683fb594bb3ffd (patch)
treec76d23c3c03eb2e45345c8e5125da2111532a551 /src/libcore/vec.rs
parent4bf5ad63f023320864dad323262364a476354d15 (diff)
parentc64a5d2d37a91e2151da41324a7f5dfc2b9c05d3 (diff)
downloadrust-c3fe0b97de67e0449aa20cd8ef683fb594bb3ffd.tar.gz
rust-c3fe0b97de67e0449aa20cd8ef683fb594bb3ffd.zip
auto merge of #5369 : thestinger/rust/iter, r=z0w0
This can eventually be implemented on other sequence containers like `deque` (it's missing `each` too at the moment).
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 2c447b3e4ae..360940236ca 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1357,7 +1357,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 {
@@ -2280,11 +2280,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()) }
 }
@@ -2305,6 +2303,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)