Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 如何使用人造丝进行枚举迭代?_Multithreading_For Loop_Rust_Iterator_Rayon - Fatal编程技术网

Multithreading 如何使用人造丝进行枚举迭代?

Multithreading 如何使用人造丝进行枚举迭代?,multithreading,for-loop,rust,iterator,rayon,Multithreading,For Loop,Rust,Iterator,Rayon,我可以迭代和处理索引和变量,例如: let x = vec![5, 6, 7, 8]; for (index, val) in x.iter().enumerate() { println!("{} {}", val, index); } 现在对于rayon,据我所知,通过par_iter()的并行迭代不支持enumerate,因为它有ParallelIterator 人造丝似乎有IndexedParallelIterator,但我不知道如何使用它来产生与上面所示

我可以迭代和处理索引和变量,例如:

let x = vec![5, 6, 7, 8];

for (index, val) in x.iter().enumerate() {
    println!("{} {}", val, index);
}
现在对于rayon,据我所知,通过
par_iter()
的并行迭代不支持enumerate,因为它有
ParallelIterator

人造丝似乎有
IndexedParallelIterator
,但我不知道如何使用它来产生与上面所示的简单for循环类似的结果

在并行迭代时,是否仍然可以跟踪每个值的索引?简单for循环是什么样子的?

当您通过调用从创建时,它同时也是一个,这样您就可以调用它来获取项目索引,如下所示:

//rayon=“1.5”
使用人造丝::前奏::*;
fn main(){
设x=vec![5,6,7,8];
x、 par_iter().enumerate().for_each(|(index,val)|{
println!(“{}{}”,val,index);
});
}