Skip to content

Commit b1eb457

Browse files
committed
core: Improve the docs and signature of vec::iter2
1 parent d6ded67 commit b1eb457

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/libcore/vec.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,19 @@ fn iter_between<T>(v: [const T], start: uint, end: uint, f: fn(T)) {
773773
}
774774
}
775775

776-
#[doc = "Iterates over two vectors in parallel"]
776+
#[doc = "
777+
Iterates over two vectors simultaneously
778+
779+
# Failure
780+
781+
Both vectors must have the same length
782+
"]
777783
#[inline]
778-
fn iter2<U, T>(v: [ U], v2: [const T], f: fn(U, T)) {
779-
let mut i = 0;
780-
for elt in v { f(elt, v2[i]); i += 1; }
784+
fn iter2<U, T>(v1: [const U], v2: [const T], f: fn(U, T)) {
785+
assert len(v1) == len(v2);
786+
uint::range(0u, len(v1)) {|i|
787+
f(v1[i], v2[i])
788+
}
781789
}
782790

783791
#[doc = "

0 commit comments

Comments
 (0)