summary refs log tree commit diff
path: root/src/libcore/vec.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore/vec.rs')
-rw-r--r--src/libcore/vec.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 15db86f937d..c6be27c4b77 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -75,6 +75,7 @@ export swap;
 export reverse;
 export reversed;
 export iter, iter_between, each, eachi, reach, reachi;
+export each_mut, each_const;
 export iter2;
 export iteri;
 export riter;
@@ -1174,6 +1175,24 @@ pure fn each<T>(v: &[T], f: fn(T) -> bool) {
     }
 }
 
+/// Like `each()`, but for the case where you have
+/// a vector with mutable contents and you would like
+/// to mutate the contents as you iterate.
+#[inline(always)]
+pure fn each_mut<T>(v: &[mut T], f: fn(elem: &mut T) -> bool) {
+    do vec::as_mut_buf(v) |p, n| {
+        let mut n = n;
+        let mut p = p;
+        while n > 0u {
+            unsafe {
+                if !f(&mut *p) { break; }
+                p = ptr::mut_offset(p, 1u);
+            }
+            n -= 1u;
+        }
+    }
+}
+
 /**
  * Iterates over a vector's elements and indices
  *