假設我有以下迭代器數組:
let arr = [0..9, 2..8, 4..8, 3..5];
如何創建迭代器,每次調用.next()
時從每個數組中提取一個元素,并返回包含這些內容的新數組?我查看了itertools::izip
和itertools::multizip
,但這些都不適用于數組。
在這種情況下,如果調用了這樣的函數zip_array
,我會得到以下結果:
for [a, b, c, d] in zip_array(arr) {
println!("{a} {b} {c} 8gueqo4");
}
println!("end of iteration");
// 0 2 4 3
// 1 3 5 4
// end of iteration
如何實現此功能?
在夜間,您可以使用此代碼。為了穩定,您必須在
<[_; 4]>
中指定長度。