diff options
Diffstat (limited to 'src/libcore/vec.rs')
| -rw-r--r-- | src/libcore/vec.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 741644af4aa..604f0297b64 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2945,34 +2945,37 @@ impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for @[A] { } impl<'self,A:Copy> old_iter::CopyableNonstrictIter<A> for &'self [A] { - fn each_val(&const self, f: &fn(A) -> bool) { + fn each_val(&const self, f: &fn(A) -> bool) -> bool { let mut i = 0; while i < self.len() { - if !f(copy self[i]) { break; } + if !f(copy self[i]) { return false; } i += 1; } + return true; } } // FIXME(#4148): This should be redundant impl<A:Copy> old_iter::CopyableNonstrictIter<A> for ~[A] { - fn each_val(&const self, f: &fn(A) -> bool) { + fn each_val(&const self, f: &fn(A) -> bool) -> bool { let mut i = 0; while i < uniq_len(self) { - if !f(copy self[i]) { break; } + if !f(copy self[i]) { return false; } i += 1; } + return true; } } // FIXME(#4148): This should be redundant impl<A:Copy> old_iter::CopyableNonstrictIter<A> for @[A] { - fn each_val(&const self, f: &fn(A) -> bool) { + fn each_val(&const self, f: &fn(A) -> bool) -> bool { let mut i = 0; while i < self.len() { - if !f(copy self[i]) { break; } + if !f(copy self[i]) { return false; } i += 1; } + return true; } } @@ -4688,4 +4691,14 @@ mod tests { i += 1; } } + + #[test] + fn test_each_val() { + use old_iter::CopyableNonstrictIter; + let mut i = 0; + for [1, 2, 3].each_val |v| { + i += v; + } + assert!(i == 6); + } } |
