rayon-rs/rayon

A `#[parallelized]` attribute

開放

#553 建立於 2018年3月12日

 (10 則留言) (38 個反應) (0 位負責人)Rust (450 個分叉)batch import
enhancementhelp wanted

倉庫指標

星標
 (9,410 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Once custom attributes are stable, I think it would be great to have an attribute that transforms a for loop into a parallel iterator for_each call:

#[parallelized]
for x in 0..100 {
    println!("{}", x);
}

Equivalent to:

(0..100).into_par_iter().for_each(|x| println!("{}", x));

This would be analogous to futures-await's #[async] attribute, which generates a for loop that processes a Stream.

The one nit would be that early returns would be a mistake, hopefully a compiler error, and you would probably want to do what you can to catch them while expanding the attribute.

貢獻者指南