diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-08-23 14:46:59 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-08-23 18:54:08 -0700 |
| commit | a08f3a7d4d937c2b26c8a29edabe7fb089d0b5f7 (patch) | |
| tree | 778e2d94eca68fd3e579b2ad8ac2725602afe340 /src/libcore/vec.rs | |
| parent | 83e7c869bdfadf0ed8aca92e76fc5073b63402e2 (diff) | |
| download | rust-a08f3a7d4d937c2b26c8a29edabe7fb089d0b5f7.tar.gz rust-a08f3a7d4d937c2b26c8a29edabe7fb089d0b5f7.zip | |
More complete fix to #3162 (borrowck bug related to access to rec fields)
Diffstat (limited to 'src/libcore/vec.rs')
| -rw-r--r-- | src/libcore/vec.rs | 19 |
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 * |
