You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1090 lines
461 KiB
1090 lines
461 KiB
5 years ago
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `ParallelIterator` trait in crate `rayon`."><meta name="keywords" content="rust, rustlang, rust-lang, ParallelIterator"><title>rayon::iter::ParallelIterator - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../rayon/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><p class='location'>Trait ParallelIterator</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#associated-types">Associated Types</a><div class="sidebar-links"><a href="#associatedtype.Item">Item</a></div><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.drive_unindexed">drive_unindexed</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.all">all</a><a href="#method.any">any</a><a href="#method.chain">chain</a><a href="#method.cloned">cloned</a><a href="#method.collect">collect</a><a href="#method.count">count</a><a href="#method.filter">filter</a><a href="#method.filter_map">filter_map</a><a href="#method.find_any">find_any</a><a href="#method.find_first">find_first</a><a href="#method.find_last">find_last</a><a href="#method.find_map_any">find_map_any</a><a href="#method.find_map_first">find_map_first</a><a href="#method.find_map_last">find_map_last</a><a href="#method.flat_map">flat_map</a><a href="#method.flatten">flatten</a><a href="#method.fold">fold</a><a href="#method.fold_with">fold_with</a><a href="#method.for_each">for_each</a><a href="#method.for_each_init">for_each_init</a><a href="#method.for_each_with">for_each_with</a><a href="#method.inspect">inspect</a><a href="#method.intersperse">intersperse</a><a href="#method.map">map</a><a href="#method.map_init">map_init</a><a href="#method.map_with">map_with</a><a href="#method.max">max</a><a href="#method.max_by">max_by</a><a href="#method.max_by_key">max_by_key</a><a href="#method.min">min</a><a href="#method.min_by">min_by</a><a href="#method.min_by_key">min_by_key</a><a href="#method.opt_len">opt_len</a><a href="#method.panic_fuse">panic_fuse</a><a href="#method.partition">partition</a><a href="#method.partition_map">partition_map</a><a href="#method.product">product</a><a href="#method.reduce">reduce</a><a href="#method.reduce_with">reduce_with</a><a href="#method.sum">sum</a><a href="#method.try_fold">try_fold</a><a href="#method.try_fold_with">try_fold_with</a><a href="#method.try_for_each">try_for_each</a><a href="#method.try_for_each_init">try_for_each_init</a><a href="#method.try_for_each_with">try_for_each_with</a><a href="#method.try_reduce">try_reduce</a><a href="#method.try_reduce_with">try_reduce_with</a><a href="#method.unzip">unzip</a><a href="#method.update">update</a><a href="#method.while_some">while_some</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>rayon</a>::<wbr><a href='index.html'>iter</a></p><script>window.sidebarCurrent = {name: 'ParallelIterator', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></d
|
||
|
type <a href='#associatedtype.Item' class="type">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>;
|
||
|
fn <a href='#tymethod.drive_unindexed' class='fnname'>drive_unindexed</a><C>(self, consumer: C) -> C::<a class="type" href="../../rayon/iter/plumbing/trait.Consumer.html#associatedtype.Result" title="type rayon::iter::plumbing::Consumer::Result">Result</a><br> <span class="where">where<br> C: <a class="trait" href="../../rayon/iter/plumbing/trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">UnindexedConsumer</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>></span>;
|
||
|
|
||
|
fn <a href='#method.for_each' class='fnname'>for_each</a><OP>(self, op: OP)<br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.for_each_with' class='fnname'>for_each_with</a><OP, T>(self, init: T, op: OP)<br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.for_each_init' class='fnname'>for_each_init</a><OP, INIT, T>(self, init: INIT, op: OP)<br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> INIT: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_for_each' class='fnname'>try_for_each</a><OP, R>(self, op: OP) -> R<br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_for_each_with' class='fnname'>try_for_each_with</a><OP, T, R>(self, init: T, op: OP) -> R<br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,<br> R: Try<Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_for_each_init' class='fnname'>try_for_each_init</a><OP, INIT, T, R>(self, init: INIT, op: OP) -> R<br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> INIT: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.count' class='fnname'>count</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> { ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.map' class='fnname'>map</a><F, R>(self, map_op: F) -> <a class="struct" href="../../rayon/iter/struct.Map.html" title="struct rayon::iter::Map">Map</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.map_with' class='fnname'>map_with</a><F, T, R>(self, init: T, map_op: F) -> <a class="struct" href="../../rayon/iter/struct.MapWith.html" title="struct rayon::iter::MapWith">MapWith</a><Self, T, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.map_init' class='fnname'>map_init</a><F, INIT, T, R>(<br> self, <br> init: INIT, <br> map_op: F<br> ) -> <a class="struct" href="../../rayon/iter/struct.MapInit.html" title="struct rayon::iter::MapInit">MapInit</a><Self, INIT, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> INIT: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.cloned' class='fnname'>cloned</a><'a, T>(self) -> <a class="struct" href="../../rayon/iter/struct.Cloned.html" title="struct rayon::iter::Cloned">Cloned</a><Self><br> <span class="where">where<br> T: 'a + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> Self: <a class="trait" href="../../rayon/iter/trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.inspect' class='fnname'>inspect</a><OP>(self, inspect_op: OP) -> <a class="struct" href="../../rayon/iter/struct.Inspect.html" title="struct rayon::iter::Inspect">Inspect</a><Self, OP><br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.update' class='fnname'>update</a><F>(self, update_op: F) -> <a class="struct" href="../../rayon/iter/struct.Update.html" title="struct rayon::iter::Update">Update</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&mut Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.filter' class='fnname'>filter</a><P>(self, filter_op: P) -> <a class="struct" href="../../rayon/iter/struct.Filter.html" title="struct rayon::iter::Filter">Filter</a><Self, P><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.filter_map' class='fnname'>filter_map</a><P, R>(self, filter_op: P) -> <a class="struct" href="../../rayon/iter/struct.FilterMap.html" title="struct rayon::iter::FilterMap">FilterMap</a><Self, P><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.flat_map' class='fnname'>flat_map</a><F, PI>(self, map_op: F) -> <a class="struct" href="../../rayon/iter/struct.FlatMap.html" title="struct rayon::iter::FlatMap">FlatMap</a><Self, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> PI + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> PI: <a class="trait" href="../../rayon/iter/trait.IntoParallelIterator.html" title="trait rayon::iter::IntoParallelIterator">IntoParallelIterator</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.flatten' class='fnname'>flatten</a>(self) -> <a class="struct" href="../../rayon/iter/struct.Flatten.html" title="struct rayon::iter::Flatten">Flatten</a><Self><br> <span class="where">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="../../rayon/iter/trait.IntoParallelIterator.html" title="trait rayon::iter::IntoParallelIterator">IntoParallelIterator</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.reduce' class='fnname'>reduce</a><OP, ID>(self, identity: ID, op: OP) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a><br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.reduce_with' class='fnname'>reduce_with</a><OP>(self, op: OP) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_reduce' class='fnname'>try_reduce</a><T, OP, ID>(self, identity: ID, op: OP) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a><br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, T) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: Try<Ok = T></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_reduce_with' class='fnname'>try_reduce_with</a><T, OP>(self, op: OP) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, T) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: Try<Ok = T></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.fold' class='fnname'>fold</a><T, ID, F>(self, identity: ID, fold_op: F) -> <a class="struct" href="../../rayon/iter/struct.Fold.html" title="struct rayon::iter::Fold">Fold</a><Self, ID, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.fold_with' class='fnname'>fold_with</a><F, T>(self, init: T, fold_op: F) -> <a class="struct" href="../../rayon/iter/struct.FoldWith.html" title="struct rayon::iter::FoldWith">FoldWith</a><Self, T, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_fold' class='fnname'>try_fold</a><T, R, ID, F>(<br> self, <br> identity: ID, <br> fold_op: F<br> ) -> <a class="struct" href="../../rayon/iter/struct.TryFold.html" title="struct rayon::iter::TryFold">TryFold</a><Self, R, ID, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.try_fold_with' class='fnname'>try_fold_with</a><F, T, R>(<br> self, <br> init: T, <br> fold_op: F<br> ) -> <a class="struct" href="../../rayon/iter/struct.TryFoldWith.html" title="struct rayon::iter::TryFoldWith">TryFoldWith</a><Self, R, F><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.sum' class='fnname'>sum</a><S>(self) -> S<br> <span class="where">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Sum.html" title="trait core::iter::traits::accum::Sum">Sum</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Sum.html" title="trait core::iter::traits::accum::Sum">Sum</a><S></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.product' class='fnname'>product</a><P>(self) -> P<br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Product.html" title="trait core::iter::traits::accum::Product">Product</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Product.html" title="trait core::iter::traits::accum::Product">Product</a><P></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.min' class='fnname'>min</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.min_by' class='fnname'>min_by</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, &Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.min_by_key' class='fnname'>min_by_key</a><K, F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> K</span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.max' class='fnname'>max</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.max_by' class='fnname'>max_by</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, &Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.max_by_key' class='fnname'>max_by_key</a><K, F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> K</span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.chain' class='fnname'>chain</a><C>(self, chain: C) -> <a class="struct" href="../../rayon/iter/struct.Chain.html" title="struct rayon::iter::Chain">Chain</a><Self, C::<a class="type" href="../../rayon/iter/trait.IntoParallelIterator.html#associatedtype.Iter" title="type rayon::iter::IntoParallelIterator::Iter">Iter</a>><br> <span class="where">where<br> C: <a class="trait" href="../../rayon/iter/trait.IntoParallelIterator.html" title="trait rayon::iter::IntoParallelIterator">IntoParallelIterator</a><Item = Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.find_any' class='fnname'>find_any</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.find_first' class='fnname'>find_first</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.find_last' class='fnname'>find_last</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.find_map_any' class='fnname'>find_map_any</a><P, R>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.find_map_first' class='fnname'>find_map_first</a><P, R>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.find_map_last' class='fnname'>find_map_last</a><P, R>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.any' class='fnname'>any</a><P>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.all' class='fnname'>all</a><P>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a><br> <span class="where">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.while_some' class='fnname'>while_some</a><T>(self) -> <a class="struct" href="../../rayon/iter/struct.WhileSome.html" title="struct rayon::iter::WhileSome">WhileSome</a><Self><br> <span class="where">where<br> Self: <a class="trait" href="../../rayon/iter/trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.panic_fuse' class='fnname'>panic_fuse</a>(self) -> <a class="struct" href="../../rayon/iter/struct.PanicFuse.html" title="struct rayon::iter::PanicFuse">PanicFuse</a><Self> { ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.collect' class='fnname'>collect</a><C>(self) -> C<br> <span class="where">where<br> C: <a class="trait" href="../../rayon/iter/trait.FromParallelIterator.html" title="trait rayon::iter::FromParallelIterator">FromParallelIterator</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.unzip' class='fnname'>unzip</a><A, B, FromA, FromB>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>FromA, FromB<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a><br> <span class="where">where<br> Self: <a class="trait" href="../../rayon/iter/trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>A, B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>>,<br> FromA: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><A>,<br> FromB: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><B>,<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.partition' class='fnname'>partition</a><A, B, P>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>A, B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a><br> <span class="where">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>,<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.partition_map' class='fnname'>partition_map</a><A, B, P, L, R>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>A, B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a><br> <span class="where">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><L>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><R>,<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="../../rayon/iter/enum.Either.html" title="enum rayon::iter::Either">Either</a><L, R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> L: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.intersperse' class='fnname'>intersperse</a>(self, element: Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="struct" href="../../rayon/iter/struct.Intersperse.html" title="struct rayon::iter::Intersperse">Intersperse</a><Self><br> <span class="where">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></span>,
|
||
|
{ ... }
|
||
|
<div class='item-spacer'></div> fn <a href='#method.opt_len' class='fnname'>opt_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>> { ... }
|
||
|
}</pre></div><div class='docblock'><p>Parallel version of the standard iterator trait.</p>
|
||
|
<p>The combinators on this trait are available on <strong>all</strong> parallel
|
||
|
iterators. Additional methods can be found on the
|
||
|
<a href="trait.IndexedParallelIterator.html"><code>IndexedParallelIterator</code></a> trait: those methods are only
|
||
|
available for parallel iterators where the number of items is
|
||
|
known in advance (so, e.g., after invoking <code>filter</code>, those methods
|
||
|
become unavailable).</p>
|
||
|
<p>For examples of using parallel iterators, see <a href="index.html">the docs on the
|
||
|
<code>iter</code> module</a>.</p>
|
||
|
</div>
|
||
|
<h2 id='associated-types' class='small-section-header'>Associated Types<a href='#associated-types' class='anchor'></a></h2><div class='methods'><h3 id='associatedtype.Item' class='method'><code id='Item.t'>type <a href='#associatedtype.Item' class="type">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></code></h3><div class='docblock'><p>The type of item that this parallel iterator produces.
|
||
|
For example, if you use the <a href="#method.for_each"><code>for_each</code></a> method, this is the type of
|
||
|
item that your closure will be invoked with.</p>
|
||
|
</div></div><span class='loading-content'>Loading content...</span>
|
||
|
<h2 id='required-methods' class='small-section-header'>Required methods<a href='#required-methods' class='anchor'></a></h2><div class='methods'><h3 id='tymethod.drive_unindexed' class='method'><code id='drive_unindexed.v'>fn <a href='#tymethod.drive_unindexed' class='fnname'>drive_unindexed</a><C>(self, consumer: C) -> C::<a class="type" href="../../rayon/iter/plumbing/trait.Consumer.html#associatedtype.Result" title="type rayon::iter::plumbing::Consumer::Result">Result</a> <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/plumbing/trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">UnindexedConsumer</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code></h3><div class='docblock'><p>Internal method used to define the behavior of this parallel
|
||
|
iterator. You should not need to call this directly.</p>
|
||
|
<p>This method causes the iterator <code>self</code> to start producing
|
||
|
items and to feed them to the consumer <code>consumer</code> one by one.
|
||
|
It may split the consumer before doing so to create the
|
||
|
opportunity to produce in parallel.</p>
|
||
|
<p>See the <a href="README.md">README</a> for more details on the internals of parallel
|
||
|
iterators.</p>
|
||
|
</div></div><span class='loading-content'>Loading content...</span>
|
||
|
<h2 id='provided-methods' class='small-section-header'>Provided methods<a href='#provided-methods' class='anchor'></a></h2><div class='methods'><h3 id='method.for_each' class='method'><code id='for_each.v'>fn <a href='#method.for_each' class='fnname'>for_each</a><OP>(self, op: OP) <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Executes <code>OP</code> on each item produced by the iterator, in parallel.</p>
|
||
|
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
(<span class="number">0</span>..<span class="number">100</span>).<span class="ident">into_par_iter</span>().<span class="ident">for_each</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?}"</span>, <span class="ident">x</span>));</pre></div>
|
||
|
</div><h3 id='method.for_each_with' class='method'><code id='for_each_with.v'>fn <a href='#method.for_each_with' class='fnname'>for_each_with</a><OP, T>(self, init: T, op: OP) <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></code></h3><div class='docblock'><p>Executes <code>OP</code> on the given <code>init</code> value with each item produced by
|
||
|
the iterator, in parallel.</p>
|
||
|
<p>The <code>init</code> value will be cloned only as needed to be paired with
|
||
|
the group of items in each rayon job. It does not require the type
|
||
|
to be <code>Sync</code>.</p>
|
||
|
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">mpsc</span>::<span class="ident">channel</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">sender</span>, <span class="ident">receiver</span>) <span class="op">=</span> <span class="ident">channel</span>();
|
||
|
|
||
|
(<span class="number">0</span>..<span class="number">5</span>).<span class="ident">into_par_iter</span>().<span class="ident">for_each_with</span>(<span class="ident">sender</span>, <span class="op">|</span><span class="ident">s</span>, <span class="ident">x</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">send</span>(<span class="ident">x</span>).<span class="ident">unwrap</span>());
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">res</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">receiver</span>.<span class="ident">iter</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="ident">res</span>.<span class="ident">sort</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">res</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>])</pre></div>
|
||
|
</div><h3 id='method.for_each_init' class='method'><code id='for_each_init.v'>fn <a href='#method.for_each_init' class='fnname'>for_each_init</a><OP, INIT, T>(self, init: INIT, op: OP) <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> INIT: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Executes <code>OP</code> on a value returned by <code>init</code> with each item produced by
|
||
|
the iterator, in parallel.</p>
|
||
|
<p>The <code>init</code> function will be called only as needed for a value to be
|
||
|
paired with the group of items in each rayon job. There is no
|
||
|
constraint on that returned type at all!</p>
|
||
|
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rand</span>;
|
||
|
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rayon</span>;
|
||
|
|
||
|
<span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">Rng</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0u8</span>; <span class="number">1_000_000</span>];
|
||
|
|
||
|
<span class="ident">v</span>.<span class="ident">par_chunks_mut</span>(<span class="number">1000</span>)
|
||
|
.<span class="ident">for_each_init</span>(
|
||
|
<span class="op">|</span><span class="op">|</span> <span class="ident">rand</span>::<span class="ident">thread_rng</span>(),
|
||
|
<span class="op">|</span><span class="ident">rng</span>, <span class="ident">chunk</span><span class="op">|</span> <span class="ident">rng</span>.<span class="ident">fill</span>(<span class="ident">chunk</span>),
|
||
|
);
|
||
|
|
||
|
<span class="comment">// There's a remote chance that this will fail...</span>
|
||
|
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0u8</span>..<span class="op">=</span><span class="number">255</span> {
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">contains</span>(<span class="kw-2">&</span><span class="ident">i</span>));
|
||
|
}</pre></div>
|
||
|
</div><h3 id='method.try_for_each' class='method'><code id='try_for_each.v'>fn <a href='#method.try_for_each' class='fnname'>try_for_each</a><OP, R>(self, op: OP) -> R <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Executes a fallible <code>OP</code> on each item produced by the iterator, in parallel.</p>
|
||
|
<p>If the <code>OP</code> returns <code>Result::Err</code> or <code>Option::None</code>, we will attempt to
|
||
|
stop processing the rest of the items in the iterator as soon as
|
||
|
possible, and we will return that terminating value. Otherwise, we will
|
||
|
return an empty <code>Result::Ok(())</code> or <code>Option::Some(())</code>. If there are
|
||
|
multiple errors in parallel, it is not specified which will be returned.</p>
|
||
|
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::{<span class="self">self</span>, <span class="ident">Write</span>};
|
||
|
|
||
|
<span class="comment">// This will stop iteration early if there's any write error, like</span>
|
||
|
<span class="comment">// having piped output get closed on the other end.</span>
|
||
|
(<span class="number">0</span>..<span class="number">100</span>).<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">try_for_each</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="macro">writeln</span><span class="macro">!</span>(<span class="ident">io</span>::<span class="ident">stdout</span>(), <span class="string">"{:?}"</span>, <span class="ident">x</span>))
|
||
|
.<span class="ident">expect</span>(<span class="string">"expected no write errors"</span>);</pre></div>
|
||
|
</div><h3 id='method.try_for_each_with' class='method'><code id='try_for_each_with.v'>fn <a href='#method.try_for_each_with' class='fnname'>try_for_each_with</a><OP, T, R>(self, init: T, op: OP) -> R <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,<br> R: Try<Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Executes a fallible <code>OP</code> on the given <code>init</code> value with each item
|
||
|
produced by the iterator, in parallel.</p>
|
||
|
<p>This combines the <code>init</code> semantics of <a href="#method.for_each_with"><code>for_each_with()</code></a> and the
|
||
|
failure semantics of <a href="#method.try_for_each"><code>try_for_each()</code></a>.</p>
|
||
|
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">mpsc</span>::<span class="ident">channel</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">sender</span>, <span class="ident">receiver</span>) <span class="op">=</span> <span class="ident">channel</span>();
|
||
|
|
||
|
(<span class="number">0</span>..<span class="number">5</span>).<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">try_for_each_with</span>(<span class="ident">sender</span>, <span class="op">|</span><span class="ident">s</span>, <span class="ident">x</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">send</span>(<span class="ident">x</span>))
|
||
|
.<span class="ident">expect</span>(<span class="string">"expected no send errors"</span>);
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">res</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">receiver</span>.<span class="ident">iter</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="ident">res</span>.<span class="ident">sort</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">res</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>])</pre></div>
|
||
|
</div><h3 id='method.try_for_each_init' class='method'><code id='try_for_each_init.v'>fn <a href='#method.try_for_each_init' class='fnname'>try_for_each_init</a><OP, INIT, T, R>(self, init: INIT, op: OP) -> R <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> INIT: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Executes a fallible <code>OP</code> on a value returned by <code>init</code> with each item
|
||
|
produced by the iterator, in parallel.</p>
|
||
|
<p>This combines the <code>init</code> semantics of <a href="#method.for_each_init"><code>for_each_init()</code></a> and the
|
||
|
failure semantics of <a href="#method.try_for_each"><code>try_for_each()</code></a>.</p>
|
||
|
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rand</span>;
|
||
|
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rayon</span>;
|
||
|
|
||
|
<span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">Rng</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0u8</span>; <span class="number">1_000_000</span>];
|
||
|
|
||
|
<span class="ident">v</span>.<span class="ident">par_chunks_mut</span>(<span class="number">1000</span>)
|
||
|
.<span class="ident">try_for_each_init</span>(
|
||
|
<span class="op">|</span><span class="op">|</span> <span class="ident">rand</span>::<span class="ident">thread_rng</span>(),
|
||
|
<span class="op">|</span><span class="ident">rng</span>, <span class="ident">chunk</span><span class="op">|</span> <span class="ident">rng</span>.<span class="ident">try_fill</span>(<span class="ident">chunk</span>),
|
||
|
)
|
||
|
.<span class="ident">expect</span>(<span class="string">"expected no rand errors"</span>);
|
||
|
|
||
|
<span class="comment">// There's a remote chance that this will fail...</span>
|
||
|
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="number">0u8</span>..<span class="op">=</span><span class="number">255</span> {
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">contains</span>(<span class="kw-2">&</span><span class="ident">i</span>));
|
||
|
}</pre></div>
|
||
|
</div><h3 id='method.count' class='method'><code id='count.v'>fn <a href='#method.count' class='fnname'>count</a>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code></h3><div class='docblock'><p>Counts the number of items in this parallel iterator.</p>
|
||
|
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">count</span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">100</span>).<span class="ident">into_par_iter</span>().<span class="ident">count</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">count</span>, <span class="number">100</span>);</pre></div>
|
||
|
</div><h3 id='method.map' class='method'><code id='map.v'>fn <a href='#method.map' class='fnname'>map</a><F, R>(self, map_op: F) -> <a class="struct" href="../../rayon/iter/struct.Map.html" title="struct rayon::iter::Map">Map</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies <code>map_op</code> to each item of this iterator, producing a new
|
||
|
iterator with the results.</p>
|
||
|
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">par_iter</span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">5</span>).<span class="ident">into_par_iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">*</span> <span class="number">2</span>);
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">doubles</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">par_iter</span>.<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">doubles</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">8</span>]);</pre></div>
|
||
|
</div><h3 id='method.map_with' class='method'><code id='map_with.v'>fn <a href='#method.map_with' class='fnname'>map_with</a><F, T, R>(self, init: T, map_op: F) -> <a class="struct" href="../../rayon/iter/struct.MapWith.html" title="struct rayon::iter::MapWith">MapWith</a><Self, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies <code>map_op</code> to the given <code>init</code> value with each item of this
|
||
|
iterator, producing a new iterator with the results.</p>
|
||
|
<p>The <code>init</code> value will be cloned only as needed to be paired with
|
||
|
the group of items in each rayon job. It does not require the type
|
||
|
to be <code>Sync</code>.</p>
|
||
|
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">mpsc</span>::<span class="ident">channel</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">sender</span>, <span class="ident">receiver</span>) <span class="op">=</span> <span class="ident">channel</span>();
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">5</span>)
|
||
|
.<span class="ident">into_par_iter</span>() <span class="comment">// iterating over i32</span>
|
||
|
.<span class="ident">map_with</span>(<span class="ident">sender</span>, <span class="op">|</span><span class="ident">s</span>, <span class="ident">x</span><span class="op">|</span> {
|
||
|
<span class="ident">s</span>.<span class="ident">send</span>(<span class="ident">x</span>).<span class="ident">unwrap</span>(); <span class="comment">// sending i32 values through the channel</span>
|
||
|
<span class="ident">x</span> <span class="comment">// returning i32</span>
|
||
|
})
|
||
|
.<span class="ident">collect</span>(); <span class="comment">// collecting the returned values into a vector</span>
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">b</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">receiver</span>.<span class="ident">iter</span>() <span class="comment">// iterating over the values in the channel</span>
|
||
|
.<span class="ident">collect</span>(); <span class="comment">// and collecting them</span>
|
||
|
<span class="ident">b</span>.<span class="ident">sort</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>, <span class="ident">b</span>);</pre></div>
|
||
|
</div><h3 id='method.map_init' class='method'><code id='map_init.v'>fn <a href='#method.map_init' class='fnname'>map_init</a><F, INIT, T, R>(<br> self, <br> init: INIT, <br> map_op: F<br>) -> <a class="struct" href="../../rayon/iter/struct.MapInit.html" title="struct rayon::iter::MapInit">MapInit</a><Self, INIT, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut </a>T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> INIT: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies <code>map_op</code> to a value returned by <code>init</code> with each item of this
|
||
|
iterator, producing a new iterator with the results.</p>
|
||
|
<p>The <code>init</code> function will be called only as needed for a value to be
|
||
|
paired with the group of items in each rayon job. There is no
|
||
|
constraint on that returned type at all!</p>
|
||
|
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rand</span>;
|
||
|
<span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">rayon</span>;
|
||
|
|
||
|
<span class="kw">use</span> <span class="ident">rand</span>::<span class="ident">Rng</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> (<span class="number">1i32</span>..<span class="number">1_000_000</span>)
|
||
|
.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">map_init</span>(
|
||
|
<span class="op">|</span><span class="op">|</span> <span class="ident">rand</span>::<span class="ident">thread_rng</span>(), <span class="comment">// get the thread-local RNG</span>
|
||
|
<span class="op">|</span><span class="ident">rng</span>, <span class="ident">x</span><span class="op">|</span> <span class="kw">if</span> <span class="ident">rng</span>.<span class="ident">gen</span>() { <span class="comment">// randomly negate items</span>
|
||
|
<span class="op">-</span><span class="ident">x</span>
|
||
|
} <span class="kw">else</span> {
|
||
|
<span class="ident">x</span>
|
||
|
},
|
||
|
).<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="comment">// There's a remote chance that this will fail...</span>
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">iter</span>().<span class="ident">any</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op"><</span> <span class="number">0</span>));
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">iter</span>().<span class="ident">any</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">></span> <span class="number">0</span>));</pre></div>
|
||
|
</div><h3 id='method.cloned' class='method'><code id='cloned.v'>fn <a href='#method.cloned' class='fnname'>cloned</a><'a, T>(self) -> <a class="struct" href="../../rayon/iter/struct.Cloned.html" title="struct rayon::iter::Cloned">Cloned</a><Self> <span class="where fmt-newline">where<br> T: 'a + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> Self: <a class="trait" href="../../rayon/iter/trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a </a>T>, </span></code></h3><div class='docblock'><p>Creates an iterator which clones all of its elements. This may be
|
||
|
useful when you have an iterator over <code>&T</code>, but you need <code>T</code>.</p>
|
||
|
<h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">v_cloned</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="comment">// cloned is the same as .map(|&x| x), for integers</span>
|
||
|
<span class="kw">let</span> <span class="ident">v_map</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">map</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span>).<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v_cloned</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v_map</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</pre></div>
|
||
|
</div><h3 id='method.inspect' class='method'><code id='inspect.v'>fn <a href='#method.inspect' class='fnname'>inspect</a><OP>(self, inspect_op: OP) -> <a class="struct" href="../../rayon/iter/struct.Inspect.html" title="struct rayon::iter::Inspect">Inspect</a><Self, OP> <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies <code>inspect_op</code> to a reference to each item of this iterator,
|
||
|
producing a new iterator passing through the original items. This is
|
||
|
often useful for debugging to see what's happening in iterator stages.</p>
|
||
|
<h1 id="examples-11" class="section-header"><a href="#examples-11">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
|
||
|
<span class="comment">// this iterator sequence is complex.</span>
|
||
|
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>()
|
||
|
.<span class="ident">cloned</span>()
|
||
|
.<span class="ident">filter</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>)
|
||
|
.<span class="ident">reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0</span>, <span class="op">|</span><span class="ident">sum</span>, <span class="ident">i</span><span class="op">|</span> <span class="ident">sum</span> <span class="op">+</span> <span class="ident">i</span>);
|
||
|
|
||
|
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">sum</span>);
|
||
|
|
||
|
<span class="comment">// let's add some inspect() calls to investigate what's happening</span>
|
||
|
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>()
|
||
|
.<span class="ident">cloned</span>()
|
||
|
.<span class="ident">inspect</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"about to filter: {}"</span>, <span class="ident">x</span>))
|
||
|
.<span class="ident">filter</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>)
|
||
|
.<span class="ident">inspect</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"made it through filter: {}"</span>, <span class="ident">x</span>))
|
||
|
.<span class="ident">reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0</span>, <span class="op">|</span><span class="ident">sum</span>, <span class="ident">i</span><span class="op">|</span> <span class="ident">sum</span> <span class="op">+</span> <span class="ident">i</span>);
|
||
|
|
||
|
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">sum</span>);</pre></div>
|
||
|
</div><h3 id='method.update' class='method'><code id='update.v'>fn <a href='#method.update' class='fnname'>update</a><F>(self, update_op: F) -> <a class="struct" href="../../rayon/iter/struct.Update.html" title="struct rayon::iter::Update">Update</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&mut Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Mutates each item of this iterator before yielding it.</p>
|
||
|
<h1 id="examples-12" class="section-header"><a href="#examples-12">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">par_iter</span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">5</span>).<span class="ident">into_par_iter</span>().<span class="ident">update</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> {<span class="kw-2">*</span><span class="ident">x</span> <span class="kw-2">*</span><span class="op">=</span> <span class="number">2</span>;});
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">doubles</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">par_iter</span>.<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">doubles</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">8</span>]);</pre></div>
|
||
|
</div><h3 id='method.filter' class='method'><code id='filter.v'>fn <a href='#method.filter' class='fnname'>filter</a><P>(self, filter_op: P) -> <a class="struct" href="../../rayon/iter/struct.Filter.html" title="struct rayon::iter::Filter">Filter</a><Self, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies <code>filter_op</code> to each item of this iterator, producing a new
|
||
|
iterator with only the items that gave <code>true</code> results.</p>
|
||
|
<h1 id="examples-13" class="section-header"><a href="#examples-13">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">par_iter</span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">10</span>).<span class="ident">into_par_iter</span>().<span class="ident">filter</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>);
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">even_numbers</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">par_iter</span>.<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">even_numbers</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>, <span class="number">8</span>]);</pre></div>
|
||
|
</div><h3 id='method.filter_map' class='method'><code id='filter_map.v'>fn <a href='#method.filter_map' class='fnname'>filter_map</a><P, R>(self, filter_op: P) -> <a class="struct" href="../../rayon/iter/struct.FilterMap.html" title="struct rayon::iter::FilterMap">FilterMap</a><Self, P> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies <code>filter_op</code> to each item of this iterator to get an <code>Option</code>,
|
||
|
producing a new iterator with only the items from <code>Some</code> results.</p>
|
||
|
<h1 id="examples-14" class="section-header"><a href="#examples-14">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">par_iter</span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">10</span>).<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">filter_map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> {
|
||
|
<span class="kw">if</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span> { <span class="prelude-val">Some</span>(<span class="ident">x</span> <span class="op">*</span> <span class="number">3</span>) }
|
||
|
<span class="kw">else</span> { <span class="prelude-val">None</span> }
|
||
|
});
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">even_numbers</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">par_iter</span>.<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">even_numbers</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">6</span>, <span class="number">12</span>, <span class="number">18</span>, <span class="number">24</span>]);</pre></div>
|
||
|
</div><h3 id='method.flat_map' class='method'><code id='flat_map.v'>fn <a href='#method.flat_map' class='fnname'>flat_map</a><F, PI>(self, map_op: F) -> <a class="struct" href="../../rayon/iter/struct.FlatMap.html" title="struct rayon::iter::FlatMap">FlatMap</a><Self, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> PI + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> PI: <a class="trait" href="../../rayon/iter/trait.IntoParallelIterator.html" title="trait rayon::iter::IntoParallelIterator">IntoParallelIterator</a>, </span></code></h3><div class='docblock'><p>Applies <code>map_op</code> to each item of this iterator to get nested iterators,
|
||
|
producing a new iterator that flattens these back into one.</p>
|
||
|
<h1 id="examples-15" class="section-header"><a href="#examples-15">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">3</span>, <span class="number">4</span>], [<span class="number">5</span>, <span class="number">6</span>], [<span class="number">7</span>, <span class="number">8</span>]];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">par_iter</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">cloned</span>().<span class="ident">flat_map</span>(<span class="op">|</span><span class="ident">a</span><span class="op">|</span> <span class="ident">a</span>.<span class="ident">to_vec</span>());
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">vec</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">par_iter</span>.<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">vec</span>[..], <span class="kw-2">&</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>]);</pre></div>
|
||
|
</div><h3 id='method.flatten' class='method'><code id='flatten.v'>fn <a href='#method.flatten' class='fnname'>flatten</a>(self) -> <a class="struct" href="../../rayon/iter/struct.Flatten.html" title="struct rayon::iter::Flatten">Flatten</a><Self> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="../../rayon/iter/trait.IntoParallelIterator.html" title="trait rayon::iter::IntoParallelIterator">IntoParallelIterator</a>, </span></code></h3><div class='docblock'><p>An adaptor that flattens iterable <code>Item</code>s into one large iterator</p>
|
||
|
<h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">x</span>: <span class="ident">Vec</span><span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span><span class="op">></span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>], <span class="macro">vec</span><span class="macro">!</span>[<span class="number">3</span>, <span class="number">4</span>]];
|
||
|
<span class="kw">let</span> <span class="ident">y</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">into_par_iter</span>().<span class="ident">flatten</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">y</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);</pre></div>
|
||
|
</div><h3 id='method.reduce' class='method'><code id='reduce.v'>fn <a href='#method.reduce' class='fnname'>reduce</a><OP, ID>(self, identity: ID, op: OP) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Reduces the items in the iterator into one item using <code>op</code>.
|
||
|
The argument <code>identity</code> should be a closure that can produce
|
||
|
"identity" value which may be inserted into the sequence as
|
||
|
needed to create opportunities for parallel execution. So, for
|
||
|
example, if you are doing a summation, then <code>identity()</code> ought
|
||
|
to produce something that represents the zero for your type
|
||
|
(but consider just calling <code>sum()</code> in that case).</p>
|
||
|
<h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="comment">// Iterate over a sequence of pairs `(x0, y0), ..., (xN, yN)`</span>
|
||
|
<span class="comment">// and use reduce to compute one pair `(x0 + ... + xN, y0 + ... + yN)`</span>
|
||
|
<span class="comment">// where the first/second elements are summed separately.</span>
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">let</span> <span class="ident">sums</span> <span class="op">=</span> [(<span class="number">0</span>, <span class="number">1</span>), (<span class="number">5</span>, <span class="number">6</span>), (<span class="number">16</span>, <span class="number">2</span>), (<span class="number">8</span>, <span class="number">9</span>)]
|
||
|
.<span class="ident">par_iter</span>() <span class="comment">// iterating over &(i32, i32)</span>
|
||
|
.<span class="ident">cloned</span>() <span class="comment">// iterating over (i32, i32)</span>
|
||
|
.<span class="ident">reduce</span>(<span class="op">|</span><span class="op">|</span> (<span class="number">0</span>, <span class="number">0</span>), <span class="comment">// the "identity" is 0 in both columns</span>
|
||
|
<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> (<span class="ident">a</span>.<span class="number">0</span> <span class="op">+</span> <span class="ident">b</span>.<span class="number">0</span>, <span class="ident">a</span>.<span class="number">1</span> <span class="op">+</span> <span class="ident">b</span>.<span class="number">1</span>));
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sums</span>, (<span class="number">0</span> <span class="op">+</span> <span class="number">5</span> <span class="op">+</span> <span class="number">16</span> <span class="op">+</span> <span class="number">8</span>, <span class="number">1</span> <span class="op">+</span> <span class="number">6</span> <span class="op">+</span> <span class="number">2</span> <span class="op">+</span> <span class="number">9</span>));</pre></div>
|
||
|
<p><strong>Note:</strong> unlike a sequential <code>fold</code> operation, the order in
|
||
|
which <code>op</code> will be applied to reduce the result is not fully
|
||
|
specified. So <code>op</code> should be <a href="https://en.wikipedia.org/wiki/Associative_property">associative</a> or else the results
|
||
|
will be non-deterministic. And of course <code>identity()</code> should
|
||
|
produce a true identity.</p>
|
||
|
</div><h3 id='method.reduce_with' class='method'><code id='reduce_with.v'>fn <a href='#method.reduce_with' class='fnname'>reduce_with</a><OP>(self, op: OP) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Reduces the items in the iterator into one item using <code>op</code>.
|
||
|
If the iterator is empty, <code>None</code> is returned; otherwise,
|
||
|
<code>Some</code> is returned.</p>
|
||
|
<p>This version of <code>reduce</code> is simple but somewhat less
|
||
|
efficient. If possible, it is better to call <code>reduce()</code>, which
|
||
|
requires an identity element.</p>
|
||
|
<h1 id="examples-18" class="section-header"><a href="#examples-18">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">let</span> <span class="ident">sums</span> <span class="op">=</span> [(<span class="number">0</span>, <span class="number">1</span>), (<span class="number">5</span>, <span class="number">6</span>), (<span class="number">16</span>, <span class="number">2</span>), (<span class="number">8</span>, <span class="number">9</span>)]
|
||
|
.<span class="ident">par_iter</span>() <span class="comment">// iterating over &(i32, i32)</span>
|
||
|
.<span class="ident">cloned</span>() <span class="comment">// iterating over (i32, i32)</span>
|
||
|
.<span class="ident">reduce_with</span>(<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> (<span class="ident">a</span>.<span class="number">0</span> <span class="op">+</span> <span class="ident">b</span>.<span class="number">0</span>, <span class="ident">a</span>.<span class="number">1</span> <span class="op">+</span> <span class="ident">b</span>.<span class="number">1</span>))
|
||
|
.<span class="ident">unwrap</span>();
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sums</span>, (<span class="number">0</span> <span class="op">+</span> <span class="number">5</span> <span class="op">+</span> <span class="number">16</span> <span class="op">+</span> <span class="number">8</span>, <span class="number">1</span> <span class="op">+</span> <span class="number">6</span> <span class="op">+</span> <span class="number">2</span> <span class="op">+</span> <span class="number">9</span>));</pre></div>
|
||
|
<p><strong>Note:</strong> unlike a sequential <code>fold</code> operation, the order in
|
||
|
which <code>op</code> will be applied to reduce the result is not fully
|
||
|
specified. So <code>op</code> should be <a href="https://en.wikipedia.org/wiki/Associative_property">associative</a> or else the results
|
||
|
will be non-deterministic.</p>
|
||
|
</div><h3 id='method.try_reduce' class='method'><code id='try_reduce.v'>fn <a href='#method.try_reduce' class='fnname'>try_reduce</a><T, OP, ID>(self, identity: ID, op: OP) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, T) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: Try<Ok = T>, </span></code></h3><div class='docblock'><p>Reduces the items in the iterator into one item using a fallible <code>op</code>.
|
||
|
The <code>identity</code> argument is used the same way as in <a href="#method.reduce"><code>reduce()</code></a>.</p>
|
||
|
<p>If a <code>Result::Err</code> or <code>Option::None</code> item is found, or if <code>op</code> reduces
|
||
|
to one, we will attempt to stop processing the rest of the items in the
|
||
|
iterator as soon as possible, and we will return that terminating value.
|
||
|
Otherwise, we will return the final reduced <code>Result::Ok(T)</code> or
|
||
|
<code>Option::Some(T)</code>. If there are multiple errors in parallel, it is not
|
||
|
specified which will be returned.</p>
|
||
|
<h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="comment">// Compute the sum of squares, being careful about overflow.</span>
|
||
|
<span class="kw">fn</span> <span class="ident">sum_squares</span><span class="op"><</span><span class="ident">I</span>: <span class="ident">IntoParallelIterator</span><span class="op"><</span><span class="ident">Item</span> <span class="op">=</span> <span class="ident">i32</span><span class="op">></span><span class="op">></span>(<span class="ident">iter</span>: <span class="ident">I</span>) <span class="op">-</span><span class="op">></span> <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> {
|
||
|
<span class="ident">iter</span>.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">i</span><span class="op">|</span> <span class="ident">i</span>.<span class="ident">checked_mul</span>(<span class="ident">i</span>)) <span class="comment">// square each item,</span>
|
||
|
.<span class="ident">try_reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0</span>, <span class="ident">i32</span>::<span class="ident">checked_add</span>) <span class="comment">// and add them up!</span>
|
||
|
}
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum_squares</span>(<span class="number">0</span>..<span class="number">5</span>), <span class="prelude-val">Some</span>(<span class="number">0</span> <span class="op">+</span> <span class="number">1</span> <span class="op">+</span> <span class="number">4</span> <span class="op">+</span> <span class="number">9</span> <span class="op">+</span> <span class="number">16</span>));
|
||
|
|
||
|
<span class="comment">// The sum might overflow</span>
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum_squares</span>(<span class="number">0</span>..<span class="number">10_000</span>), <span class="prelude-val">None</span>);
|
||
|
|
||
|
<span class="comment">// Or the squares might overflow before it even reaches `try_reduce`</span>
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum_squares</span>(<span class="number">1_000_000</span>..<span class="number">1_000_001</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
|
</div><h3 id='method.try_reduce_with' class='method'><code id='try_reduce_with.v'>fn <a href='#method.try_reduce_with' class='fnname'>try_reduce_with</a><T, OP>(self, op: OP) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> OP: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, T) -> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: Try<Ok = T>, </span></code></h3><div class='docblock'><p>Reduces the items in the iterator into one item using a fallible <code>op</code>.</p>
|
||
|
<p>Like <a href="#method.reduce_with"><code>reduce_with()</code></a>, if the iterator is empty, <code>None</code> is returned;
|
||
|
otherwise, <code>Some</code> is returned. Beyond that, it behaves like
|
||
|
<a href="#method.try_reduce"><code>try_reduce()</code></a> for handling <code>Err</code>/<code>None</code>.</p>
|
||
|
<p>For instance, with <code>Option</code> items, the return value may be:</p>
|
||
|
<ul>
|
||
|
<li><code>None</code>, the iterator was empty</li>
|
||
|
<li><code>Some(None)</code>, we stopped after encountering <code>None</code>.</li>
|
||
|
<li><code>Some(Some(x))</code>, the entire iterator reduced to <code>x</code>.</li>
|
||
|
</ul>
|
||
|
<p>With <code>Result</code> items, the nesting is more obvious:</p>
|
||
|
<ul>
|
||
|
<li><code>None</code>, the iterator was empty</li>
|
||
|
<li><code>Some(Err(e))</code>, we stopped after encountering an error <code>e</code>.</li>
|
||
|
<li><code>Some(Ok(x))</code>, the entire iterator reduced to <code>x</code>.</li>
|
||
|
</ul>
|
||
|
<h1 id="examples-20" class="section-header"><a href="#examples-20">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">files</span> <span class="op">=</span> [<span class="string">"/dev/null"</span>, <span class="string">"/does/not/exist"</span>];
|
||
|
|
||
|
<span class="comment">// Find the biggest file</span>
|
||
|
<span class="ident">files</span>.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">path</span><span class="op">|</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">metadata</span>(<span class="ident">path</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">m</span><span class="op">|</span> (<span class="ident">path</span>, <span class="ident">m</span>.<span class="ident">len</span>())))
|
||
|
.<span class="ident">try_reduce_with</span>(<span class="op">|</span><span class="ident">a</span>, <span class="ident">b</span><span class="op">|</span> {
|
||
|
<span class="prelude-val">Ok</span>(<span class="kw">if</span> <span class="ident">a</span>.<span class="number">1</span> <span class="op">></span><span class="op">=</span> <span class="ident">b</span>.<span class="number">1</span> { <span class="ident">a</span> } <span class="kw">else</span> { <span class="ident">b</span> })
|
||
|
})
|
||
|
.<span class="ident">expect</span>(<span class="string">"Some value, since the iterator is not empty"</span>)
|
||
|
.<span class="ident">expect_err</span>(<span class="string">"not found"</span>);</pre></div>
|
||
|
</div><h3 id='method.fold' class='method'><code id='fold.v'>fn <a href='#method.fold' class='fnname'>fold</a><T, ID, F>(self, identity: ID, fold_op: F) -> <a class="struct" href="../../rayon/iter/struct.Fold.html" title="struct rayon::iter::Fold">Fold</a><Self, ID, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Parallel fold is similar to sequential fold except that the
|
||
|
sequence of items may be subdivided before it is
|
||
|
folded. Consider a list of numbers like <code>22 3 77 89 46</code>. If
|
||
|
you used sequential fold to add them (<code>fold(0, |a,b| a+b)</code>,
|
||
|
you would wind up first adding 0 + 22, then 22 + 3, then 25 +
|
||
|
77, and so forth. The <strong>parallel fold</strong> works similarly except
|
||
|
that it first breaks up your list into sublists, and hence
|
||
|
instead of yielding up a single sum at the end, it yields up
|
||
|
multiple sums. The number of results is nondeterministic, as
|
||
|
is the point where the breaks occur.</p>
|
||
|
<p>So if did the same parallel fold (<code>fold(0, |a,b| a+b)</code>) on
|
||
|
our example list, we might wind up with a sequence of two numbers,
|
||
|
like so:</p>
|
||
|
<pre><code class="language-notrust">22 3 77 89 46
|
||
|
| |
|
||
|
102 135
|
||
|
</code></pre>
|
||
|
<p>Or perhaps these three numbers:</p>
|
||
|
<pre><code class="language-notrust">22 3 77 89 46
|
||
|
| | |
|
||
|
102 89 46
|
||
|
</code></pre>
|
||
|
<p>In general, Rayon will attempt to find good breaking points
|
||
|
that keep all of your cores busy.</p>
|
||
|
<h3 id="fold-versus-reduce" class="section-header"><a href="#fold-versus-reduce">Fold versus reduce</a></h3>
|
||
|
<p>The <code>fold()</code> and <code>reduce()</code> methods each take an identity element
|
||
|
and a combining function, but they operate rather differently.</p>
|
||
|
<p><code>reduce()</code> requires that the identity function has the same
|
||
|
type as the things you are iterating over, and it fully
|
||
|
reduces the list of items into a single item. So, for example,
|
||
|
imagine we are iterating over a list of bytes <code>bytes: [128_u8, 64_u8, 64_u8]</code>. If we used <code>bytes.reduce(|| 0_u8, |a: u8, b: u8| a + b)</code>, we would get an overflow. This is because <code>0</code>,
|
||
|
<code>a</code>, and <code>b</code> here are all bytes, just like the numbers in the
|
||
|
list (I wrote the types explicitly above, but those are the
|
||
|
only types you can use). To avoid the overflow, we would need
|
||
|
to do something like <code>bytes.map(|b| b as u32).reduce(|| 0, |a, b| a + b)</code>, in which case our result would be <code>256</code>.</p>
|
||
|
<p>In contrast, with <code>fold()</code>, the identity function does not
|
||
|
have to have the same type as the things you are iterating
|
||
|
over, and you potentially get back many results. So, if we
|
||
|
continue with the <code>bytes</code> example from the previous paragraph,
|
||
|
we could do <code>bytes.fold(|| 0_u32, |a, b| a + (b as u32))</code> to
|
||
|
convert our bytes into <code>u32</code>. And of course we might not get
|
||
|
back a single sum.</p>
|
||
|
<p>There is a more subtle distinction as well, though it's
|
||
|
actually implied by the above points. When you use <code>reduce()</code>,
|
||
|
your reduction function is sometimes called with values that
|
||
|
were never part of your original parallel iterator (for
|
||
|
example, both the left and right might be a partial sum). With
|
||
|
<code>fold()</code>, in contrast, the left value in the fold function is
|
||
|
always the accumulator, and the right value is always from
|
||
|
your original sequence.</p>
|
||
|
<h3 id="fold-vs-mapreduce" class="section-header"><a href="#fold-vs-mapreduce">Fold vs Map/Reduce</a></h3>
|
||
|
<p>Fold makes sense if you have some operation where it is
|
||
|
cheaper to create groups of elements at a time. For example,
|
||
|
imagine collecting characters into a string. If you were going
|
||
|
to use map/reduce, you might try this:</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span>
|
||
|
[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>]
|
||
|
.<span class="ident">par_iter</span>()
|
||
|
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">c</span>: <span class="kw-2">&</span><span class="ident">char</span><span class="op">|</span> <span class="macro">format</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">c</span>))
|
||
|
.<span class="ident">reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">String</span>::<span class="ident">new</span>(),
|
||
|
<span class="op">|</span><span class="kw-2">mut</span> <span class="ident">a</span>: <span class="ident">String</span>, <span class="ident">b</span>: <span class="ident">String</span><span class="op">|</span> { <span class="ident">a</span>.<span class="ident">push_str</span>(<span class="kw-2">&</span><span class="ident">b</span>); <span class="ident">a</span> });
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">"abcde"</span>);</pre></div>
|
||
|
<p>Because reduce produces the same type of element as its input,
|
||
|
you have to first map each character into a string, and then
|
||
|
you can reduce them. This means we create one string per
|
||
|
element in our iterator -- not so great. Using <code>fold</code>, we can
|
||
|
do this instead:</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span>
|
||
|
[<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'e'</span>]
|
||
|
.<span class="ident">par_iter</span>()
|
||
|
.<span class="ident">fold</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">String</span>::<span class="ident">new</span>(),
|
||
|
<span class="op">|</span><span class="kw-2">mut</span> <span class="ident">s</span>: <span class="ident">String</span>, <span class="ident">c</span>: <span class="kw-2">&</span><span class="ident">char</span><span class="op">|</span> { <span class="ident">s</span>.<span class="ident">push</span>(<span class="kw-2">*</span><span class="ident">c</span>); <span class="ident">s</span> })
|
||
|
.<span class="ident">reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">String</span>::<span class="ident">new</span>(),
|
||
|
<span class="op">|</span><span class="kw-2">mut</span> <span class="ident">a</span>: <span class="ident">String</span>, <span class="ident">b</span>: <span class="ident">String</span><span class="op">|</span> { <span class="ident">a</span>.<span class="ident">push_str</span>(<span class="kw-2">&</span><span class="ident">b</span>); <span class="ident">a</span> });
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">s</span>, <span class="string">"abcde"</span>);</pre></div>
|
||
|
<p>Now <code>fold</code> will process groups of our characters at a time,
|
||
|
and we only make one string per group. We should wind up with
|
||
|
some small-ish number of strings roughly proportional to the
|
||
|
number of CPUs you have (it will ultimately depend on how busy
|
||
|
your processors are). Note that we still need to do a reduce
|
||
|
afterwards to combine those groups of strings into a single
|
||
|
string.</p>
|
||
|
<p>You could use a similar trick to save partial results (e.g., a
|
||
|
cache) or something similar.</p>
|
||
|
<h3 id="combining-fold-with-other-operations" class="section-header"><a href="#combining-fold-with-other-operations">Combining fold with other operations</a></h3>
|
||
|
<p>You can combine <code>fold</code> with <code>reduce</code> if you want to produce a
|
||
|
single value. This is then roughly equivalent to a map/reduce
|
||
|
combination in effect:</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="number">0</span>..<span class="number">22_u8</span>;
|
||
|
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">bytes</span>.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">fold</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0_u32</span>, <span class="op">|</span><span class="ident">a</span>: <span class="ident">u32</span>, <span class="ident">b</span>: <span class="ident">u8</span><span class="op">|</span> <span class="ident">a</span> <span class="op">+</span> (<span class="ident">b</span> <span class="kw">as</span> <span class="ident">u32</span>))
|
||
|
.<span class="ident">sum</span>::<span class="op"><</span><span class="ident">u32</span><span class="op">></span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>, (<span class="number">0</span>..<span class="number">22</span>).<span class="ident">sum</span>()); <span class="comment">// compare to sequential</span></pre></div>
|
||
|
</div><h3 id='method.fold_with' class='method'><code id='fold_with.v'>fn <a href='#method.fold_with' class='fnname'>fold_with</a><F, T>(self, init: T, fold_op: F) -> <a class="struct" href="../../rayon/iter/struct.FoldWith.html" title="struct rayon::iter::FoldWith">FoldWith</a><Self, T, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></code></h3><div class='docblock'><p>Applies <code>fold_op</code> to the given <code>init</code> value with each item of this
|
||
|
iterator, finally producing the value for further use.</p>
|
||
|
<p>This works essentially like <code>fold(|| init.clone(), fold_op)</code>, except
|
||
|
it doesn't require the <code>init</code> type to be <code>Sync</code>, nor any other form
|
||
|
of added synchronization.</p>
|
||
|
<h1 id="examples-21" class="section-header"><a href="#examples-21">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="number">0</span>..<span class="number">22_u8</span>;
|
||
|
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">bytes</span>.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">fold_with</span>(<span class="number">0_u32</span>, <span class="op">|</span><span class="ident">a</span>: <span class="ident">u32</span>, <span class="ident">b</span>: <span class="ident">u8</span><span class="op">|</span> <span class="ident">a</span> <span class="op">+</span> (<span class="ident">b</span> <span class="kw">as</span> <span class="ident">u32</span>))
|
||
|
.<span class="ident">sum</span>::<span class="op"><</span><span class="ident">u32</span><span class="op">></span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>, (<span class="number">0</span>..<span class="number">22</span>).<span class="ident">sum</span>()); <span class="comment">// compare to sequential</span></pre></div>
|
||
|
</div><h3 id='method.try_fold' class='method'><code id='try_fold.v'>fn <a href='#method.try_fold' class='fnname'>try_fold</a><T, R, ID, F>(<br> self, <br> identity: ID, <br> fold_op: F<br>) -> <a class="struct" href="../../rayon/iter/struct.TryFold.html" title="struct rayon::iter::TryFold">TryFold</a><Self, R, ID, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> ID: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>() -> T + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Perform a fallible parallel fold.</p>
|
||
|
<p>This is a variation of <a href="#method.fold"><code>fold()</code></a> for operations which can fail with
|
||
|
<code>Option::None</code> or <code>Result::Err</code>. The first such failure stops
|
||
|
processing the local set of items, without affecting other folds in the
|
||
|
iterator's subdivisions.</p>
|
||
|
<p>Often, <code>try_fold()</code> will be followed by <a href="#method.try_reduce"><code>try_reduce()</code></a>
|
||
|
for a final reduction and global short-circuiting effect.</p>
|
||
|
<h1 id="examples-22" class="section-header"><a href="#examples-22">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="number">0</span>..<span class="number">22_u8</span>;
|
||
|
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">bytes</span>.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">try_fold</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0_u32</span>, <span class="op">|</span><span class="ident">a</span>: <span class="ident">u32</span>, <span class="ident">b</span>: <span class="ident">u8</span><span class="op">|</span> <span class="ident">a</span>.<span class="ident">checked_add</span>(<span class="ident">b</span> <span class="kw">as</span> <span class="ident">u32</span>))
|
||
|
.<span class="ident">try_reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0</span>, <span class="ident">u32</span>::<span class="ident">checked_add</span>);
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>, <span class="prelude-val">Some</span>((<span class="number">0</span>..<span class="number">22</span>).<span class="ident">sum</span>())); <span class="comment">// compare to sequential</span></pre></div>
|
||
|
</div><h3 id='method.try_fold_with' class='method'><code id='try_fold_with.v'>fn <a href='#method.try_fold_with' class='fnname'>try_fold_with</a><F, T, R>(self, init: T, fold_op: F) -> <a class="struct" href="../../rayon/iter/struct.TryFoldWith.html" title="struct rayon::iter::TryFoldWith">TryFoldWith</a><Self, R, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(T, Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: Try<Ok = T> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Perform a fallible parallel fold with a cloneable <code>init</code> value.</p>
|
||
|
<p>This combines the <code>init</code> semantics of <a href="#method.fold_with"><code>fold_with()</code></a> and the failure
|
||
|
semantics of <a href="#method.try_fold"><code>try_fold()</code></a>.</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="number">0</span>..<span class="number">22_u8</span>;
|
||
|
<span class="kw">let</span> <span class="ident">sum</span> <span class="op">=</span> <span class="ident">bytes</span>.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">try_fold_with</span>(<span class="number">0_u32</span>, <span class="op">|</span><span class="ident">a</span>: <span class="ident">u32</span>, <span class="ident">b</span>: <span class="ident">u8</span><span class="op">|</span> <span class="ident">a</span>.<span class="ident">checked_add</span>(<span class="ident">b</span> <span class="kw">as</span> <span class="ident">u32</span>))
|
||
|
.<span class="ident">try_reduce</span>(<span class="op">|</span><span class="op">|</span> <span class="number">0</span>, <span class="ident">u32</span>::<span class="ident">checked_add</span>);
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>, <span class="prelude-val">Some</span>((<span class="number">0</span>..<span class="number">22</span>).<span class="ident">sum</span>())); <span class="comment">// compare to sequential</span></pre></div>
|
||
|
</div><h3 id='method.sum' class='method'><code id='sum.v'>fn <a href='#method.sum' class='fnname'>sum</a><S>(self) -> S <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Sum.html" title="trait core::iter::traits::accum::Sum">Sum</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Sum.html" title="trait core::iter::traits::accum::Sum">Sum</a><S>, </span></code></h3><div class='docblock'><p>Sums up the items in the iterator.</p>
|
||
|
<p>Note that the order in items will be reduced is not specified,
|
||
|
so if the <code>+</code> operator is not truly <a href="https://en.wikipedia.org/wiki/Associative_property">associative</a> (as is the
|
||
|
case for floating point numbers), then the results are not
|
||
|
fully deterministic.</p>
|
||
|
<p>Basically equivalent to <code>self.reduce(|| 0, |a, b| a + b)</code>,
|
||
|
except that the type of <code>0</code> and the <code>+</code> operation may vary
|
||
|
depending on the type of value being produced.</p>
|
||
|
<h1 id="examples-23" class="section-header"><a href="#examples-23">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">5</span>, <span class="number">7</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">sum</span>: <span class="ident">i32</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">sum</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sum</span>, <span class="number">13</span>);</pre></div>
|
||
|
</div><h3 id='method.product' class='method'><code id='product.v'>fn <a href='#method.product' class='fnname'>product</a><P>(self) -> P <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Product.html" title="trait core::iter::traits::accum::Product">Product</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/accum/trait.Product.html" title="trait core::iter::traits::accum::Product">Product</a><P>, </span></code></h3><div class='docblock'><p>Multiplies all the items in the iterator.</p>
|
||
|
<p>Note that the order in items will be reduced is not specified,
|
||
|
so if the <code>*</code> operator is not truly <a href="https://en.wikipedia.org/wiki/Associative_property">associative</a> (as is the
|
||
|
case for floating point numbers), then the results are not
|
||
|
fully deterministic.</p>
|
||
|
<p>Basically equivalent to <code>self.reduce(|| 1, |a, b| a * b)</code>,
|
||
|
except that the type of <code>1</code> and the <code>*</code> operation may vary
|
||
|
depending on the type of value being produced.</p>
|
||
|
<h1 id="examples-24" class="section-header"><a href="#examples-24">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">fn</span> <span class="ident">factorial</span>(<span class="ident">n</span>: <span class="ident">u32</span>) <span class="op">-</span><span class="op">></span> <span class="ident">u32</span> {
|
||
|
(<span class="number">1</span>..<span class="ident">n</span><span class="op">+</span><span class="number">1</span>).<span class="ident">into_par_iter</span>().<span class="ident">product</span>()
|
||
|
}
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">factorial</span>(<span class="number">0</span>), <span class="number">1</span>);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">factorial</span>(<span class="number">1</span>), <span class="number">1</span>);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">factorial</span>(<span class="number">5</span>), <span class="number">120</span>);</pre></div>
|
||
|
</div><h3 id='method.min' class='method'><code id='min.v'>fn <a href='#method.min' class='fnname'>min</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></code></h3><div class='docblock'><p>Computes the minimum of all the items in the iterator. If the
|
||
|
iterator is empty, <code>None</code> is returned; otherwise, <code>Some(min)</code>
|
||
|
is returned.</p>
|
||
|
<p>Note that the order in which the items will be reduced is not
|
||
|
specified, so if the <code>Ord</code> impl is not truly associative, then
|
||
|
the results are not deterministic.</p>
|
||
|
<p>Basically equivalent to <code>self.reduce_with(|a, b| cmp::min(a, b))</code>.</p>
|
||
|
<h1 id="examples-25" class="section-header"><a href="#examples-25">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">45</span>, <span class="number">74</span>, <span class="number">32</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">min</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">32</span>));
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">b</span>: [<span class="ident">i32</span>; <span class="number">0</span>] <span class="op">=</span> [];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">b</span>.<span class="ident">par_iter</span>().<span class="ident">min</span>(), <span class="prelude-val">None</span>);</pre></div>
|
||
|
</div><h3 id='method.min_by' class='method'><code id='min_by.v'>fn <a href='#method.min_by' class='fnname'>min_by</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, &Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></code></h3><div class='docblock'><p>Computes the minimum of all the items in the iterator with respect to
|
||
|
the given comparison function. If the iterator is empty, <code>None</code> is
|
||
|
returned; otherwise, <code>Some(min)</code> is returned.</p>
|
||
|
<p>Note that the order in which the items will be reduced is not
|
||
|
specified, so if the comparison function is not associative, then
|
||
|
the results are not deterministic.</p>
|
||
|
<h1 id="examples-26" class="section-header"><a href="#examples-26">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="op">-</span><span class="number">3_i32</span>, <span class="number">77</span>, <span class="number">53</span>, <span class="number">240</span>, <span class="op">-</span><span class="number">1</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">min_by</span>(<span class="op">|</span><span class="ident">x</span>, <span class="ident">y</span><span class="op">|</span> <span class="ident">x</span>.<span class="ident">cmp</span>(<span class="ident">y</span>)), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="op">-</span><span class="number">3</span>));</pre></div>
|
||
|
</div><h3 id='method.min_by_key' class='method'><code id='min_by_key.v'>fn <a href='#method.min_by_key' class='fnname'>min_by_key</a><K, F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> K, </span></code></h3><div class='docblock'><p>Computes the item that yields the minimum value for the given
|
||
|
function. If the iterator is empty, <code>None</code> is returned;
|
||
|
otherwise, <code>Some(item)</code> is returned.</p>
|
||
|
<p>Note that the order in which the items will be reduced is not
|
||
|
specified, so if the <code>Ord</code> impl is not truly associative, then
|
||
|
the results are not deterministic.</p>
|
||
|
<h1 id="examples-27" class="section-header"><a href="#examples-27">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="op">-</span><span class="number">3_i32</span>, <span class="number">34</span>, <span class="number">2</span>, <span class="number">5</span>, <span class="op">-</span><span class="number">10</span>, <span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">23</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">min_by_key</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span>.<span class="ident">abs</span>()), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">2</span>));</pre></div>
|
||
|
</div><h3 id='method.max' class='method'><code id='max.v'>fn <a href='#method.max' class='fnname'>max</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>, </span></code></h3><div class='docblock'><p>Computes the maximum of all the items in the iterator. If the
|
||
|
iterator is empty, <code>None</code> is returned; otherwise, <code>Some(max)</code>
|
||
|
is returned.</p>
|
||
|
<p>Note that the order in which the items will be reduced is not
|
||
|
specified, so if the <code>Ord</code> impl is not truly associative, then
|
||
|
the results are not deterministic.</p>
|
||
|
<p>Basically equivalent to <code>self.reduce_with(|a, b| cmp::max(a, b))</code>.</p>
|
||
|
<h1 id="examples-28" class="section-header"><a href="#examples-28">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">45</span>, <span class="number">74</span>, <span class="number">32</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">max</span>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">74</span>));
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">b</span>: [<span class="ident">i32</span>; <span class="number">0</span>] <span class="op">=</span> [];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">b</span>.<span class="ident">par_iter</span>().<span class="ident">max</span>(), <span class="prelude-val">None</span>);</pre></div>
|
||
|
</div><h3 id='method.max_by' class='method'><code id='max_by.v'>fn <a href='#method.max_by' class='fnname'>max_by</a><F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>, &Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>, </span></code></h3><div class='docblock'><p>Computes the maximum of all the items in the iterator with respect to
|
||
|
the given comparison function. If the iterator is empty, <code>None</code> is
|
||
|
returned; otherwise, <code>Some(min)</code> is returned.</p>
|
||
|
<p>Note that the order in which the items will be reduced is not
|
||
|
specified, so if the comparison function is not associative, then
|
||
|
the results are not deterministic.</p>
|
||
|
<h1 id="examples-29" class="section-header"><a href="#examples-29">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="op">-</span><span class="number">3_i32</span>, <span class="number">77</span>, <span class="number">53</span>, <span class="number">240</span>, <span class="op">-</span><span class="number">1</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">max_by</span>(<span class="op">|</span><span class="ident">x</span>, <span class="ident">y</span><span class="op">|</span> <span class="ident">x</span>.<span class="ident">abs</span>().<span class="ident">cmp</span>(<span class="kw-2">&</span><span class="ident">y</span>.<span class="ident">abs</span>())), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">240</span>));</pre></div>
|
||
|
</div><h3 id='method.max_by_key' class='method'><code id='max_by_key.v'>fn <a href='#method.max_by_key' class='fnname'>max_by_key</a><K, F>(self, f: F) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> K, </span></code></h3><div class='docblock'><p>Computes the item that yields the maximum value for the given
|
||
|
function. If the iterator is empty, <code>None</code> is returned;
|
||
|
otherwise, <code>Some(item)</code> is returned.</p>
|
||
|
<p>Note that the order in which the items will be reduced is not
|
||
|
specified, so if the <code>Ord</code> impl is not truly associative, then
|
||
|
the results are not deterministic.</p>
|
||
|
<h1 id="examples-30" class="section-header"><a href="#examples-30">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="op">-</span><span class="number">3_i32</span>, <span class="number">34</span>, <span class="number">2</span>, <span class="number">5</span>, <span class="op">-</span><span class="number">10</span>, <span class="op">-</span><span class="number">3</span>, <span class="op">-</span><span class="number">23</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">max_by_key</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span>.<span class="ident">abs</span>()), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">34</span>));</pre></div>
|
||
|
</div><h3 id='method.chain' class='method'><code id='chain.v'>fn <a href='#method.chain' class='fnname'>chain</a><C>(self, chain: C) -> <a class="struct" href="../../rayon/iter/struct.Chain.html" title="struct rayon::iter::Chain">Chain</a><Self, C::<a class="type" href="../../rayon/iter/trait.IntoParallelIterator.html#associatedtype.Iter" title="type rayon::iter::IntoParallelIterator::Iter">Iter</a>> <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/trait.IntoParallelIterator.html" title="trait rayon::iter::IntoParallelIterator">IntoParallelIterator</a><Item = Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code></h3><div class='docblock'><p>Takes two iterators and creates a new iterator over both.</p>
|
||
|
<h1 id="examples-31" class="section-header"><a href="#examples-31">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>];
|
||
|
<span class="kw">let</span> <span class="ident">b</span> <span class="op">=</span> [<span class="number">9</span>, <span class="number">8</span>, <span class="number">7</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">par_iter</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">chain</span>(<span class="ident">b</span>.<span class="ident">par_iter</span>());
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">chained</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">par_iter</span>.<span class="ident">cloned</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">&</span><span class="ident">chained</span>[..], <span class="kw-2">&</span>[<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">9</span>, <span class="number">8</span>, <span class="number">7</span>]);</pre></div>
|
||
|
</div><h3 id='method.find_any' class='method'><code id='find_any.v'>fn <a href='#method.find_any' class='fnname'>find_any</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Searches for <strong>some</strong> item in the parallel iterator that
|
||
|
matches the given predicate and returns it. This operation
|
||
|
is similar to <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.find"><code>find</code> on sequential iterators</a> but
|
||
|
the item returned may not be the <strong>first</strong> one in the parallel
|
||
|
sequence which matches, since we search the entire sequence in parallel.</p>
|
||
|
<p>Once a match is found, we will attempt to stop processing
|
||
|
the rest of the items in the iterator as soon as possible
|
||
|
(just as <code>find</code> stops iterating once a match is found).</p>
|
||
|
<h1 id="examples-32" class="section-header"><a href="#examples-32">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">find_any</span>(<span class="op">|</span><span class="kw-2">&</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">3</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">3</span>));
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">find_any</span>(<span class="op">|</span><span class="kw-2">&</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">100</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
|
</div><h3 id='method.find_first' class='method'><code id='find_first.v'>fn <a href='#method.find_first' class='fnname'>find_first</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Searches for the sequentially <strong>first</strong> item in the parallel iterator
|
||
|
that matches the given predicate and returns it.</p>
|
||
|
<p>Once a match is found, all attempts to the right of the match
|
||
|
will be stopped, while attempts to the left must continue in case
|
||
|
an earlier match is found.</p>
|
||
|
<p>Note that not all parallel iterators have a useful order, much like
|
||
|
sequential <code>HashMap</code> iteration, so "first" may be nebulous. If you
|
||
|
just want the first match that discovered anywhere in the iterator,
|
||
|
<code>find_any</code> is a better choice.</p>
|
||
|
<h1 id="examples-33" class="section-header"><a href="#examples-33">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">find_first</span>(<span class="op">|</span><span class="kw-2">&</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">3</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">3</span>));
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">find_first</span>(<span class="op">|</span><span class="kw-2">&</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">100</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
|
</div><h3 id='method.find_last' class='method'><code id='find_last.v'>fn <a href='#method.find_last' class='fnname'>find_last</a><P>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Searches for the sequentially <strong>last</strong> item in the parallel iterator
|
||
|
that matches the given predicate and returns it.</p>
|
||
|
<p>Once a match is found, all attempts to the left of the match
|
||
|
will be stopped, while attempts to the right must continue in case
|
||
|
a later match is found.</p>
|
||
|
<p>Note that not all parallel iterators have a useful order, much like
|
||
|
sequential <code>HashMap</code> iteration, so "last" may be nebulous. When the
|
||
|
order doesn't actually matter to you, <code>find_any</code> is a better choice.</p>
|
||
|
<h1 id="examples-34" class="section-header"><a href="#examples-34">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">3</span>];
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">find_last</span>(<span class="op">|</span><span class="kw-2">&</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">3</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="number">3</span>));
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">find_last</span>(<span class="op">|</span><span class="kw-2">&</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">=</span><span class="op">=</span> <span class="number">100</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
|
</div><h3 id='method.find_map_any' class='method'><code id='find_map_any.v'>fn <a href='#method.find_map_any' class='fnname'>find_map_any</a><P, R>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies the given predicate to the items in the parallel iterator
|
||
|
and returns <strong>any</strong> non-None result of the map operation.</p>
|
||
|
<p>Once a non-None value is produced from the map operation, we will
|
||
|
attempt to stop processing the rest of the items in the iterator
|
||
|
as soon as possible.</p>
|
||
|
<p>Note that this method only returns <strong>some</strong> item in the parallel
|
||
|
iterator that is not None from the map predicate. The item returned
|
||
|
may not be the <strong>first</strong> non-None value produced in the parallel
|
||
|
sequence, since the entire sequence is mapped over in parallel.</p>
|
||
|
<h1 id="examples-35" class="section-header"><a href="#examples-35">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> [<span class="string">"lol"</span>, <span class="string">"NaN"</span>, <span class="string">"5"</span>, <span class="string">"5"</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">first_number</span> <span class="op">=</span> <span class="ident">c</span>.<span class="ident">par_iter</span>().<span class="ident">find_map_first</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">parse</span>().<span class="ident">ok</span>());
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">first_number</span>, <span class="prelude-val">Some</span>(<span class="number">5</span>));</pre></div>
|
||
|
</div><h3 id='method.find_map_first' class='method'><code id='find_map_first.v'>fn <a href='#method.find_map_first' class='fnname'>find_map_first</a><P, R>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies the given predicate to the items in the parallel iterator and
|
||
|
returns the sequentially <strong>first</strong> non-None result of the map operation.</p>
|
||
|
<p>Once a non-None value is produced from the map operation, all attempts
|
||
|
to the right of the match will be stopped, while attempts to the left
|
||
|
must continue in case an earlier match is found.</p>
|
||
|
<p>Note that not all parallel iterators have a useful order, much like
|
||
|
sequential <code>HashMap</code> iteration, so "first" may be nebulous. If you
|
||
|
just want the first non-None value discovered anywhere in the iterator,
|
||
|
<code>find_map_any</code> is a better choice.</p>
|
||
|
<h1 id="examples-36" class="section-header"><a href="#examples-36">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> [<span class="string">"lol"</span>, <span class="string">"NaN"</span>, <span class="string">"2"</span>, <span class="string">"5"</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">first_number</span> <span class="op">=</span> <span class="ident">c</span>.<span class="ident">par_iter</span>().<span class="ident">find_map_first</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">parse</span>().<span class="ident">ok</span>());
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">first_number</span>, <span class="prelude-val">Some</span>(<span class="number">2</span>));</pre></div>
|
||
|
</div><h3 id='method.find_map_last' class='method'><code id='find_map_last.v'>fn <a href='#method.find_map_last' class='fnname'>find_map_last</a><P, R>(self, predicate: P) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Applies the given predicate to the items in the parallel iterator and
|
||
|
returns the sequentially <strong>last</strong> non-None result of the map operation.</p>
|
||
|
<p>Once a non-None value is produced from the map operation, all attempts
|
||
|
to the left of the match will be stopped, while attempts to the right
|
||
|
must continue in case a later match is found.</p>
|
||
|
<p>Note that not all parallel iterators have a useful order, much like
|
||
|
sequential <code>HashMap</code> iteration, so "first" may be nebulous. If you
|
||
|
just want the first non-None value discovered anywhere in the iterator,
|
||
|
<code>find_map_any</code> is a better choice.</p>
|
||
|
<h1 id="examples-37" class="section-header"><a href="#examples-37">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">c</span> <span class="op">=</span> [<span class="string">"lol"</span>, <span class="string">"NaN"</span>, <span class="string">"2"</span>, <span class="string">"5"</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">first_number</span> <span class="op">=</span> <span class="ident">c</span>.<span class="ident">par_iter</span>().<span class="ident">find_map_last</span>(<span class="op">|</span><span class="ident">s</span><span class="op">|</span> <span class="ident">s</span>.<span class="ident">parse</span>().<span class="ident">ok</span>());
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">first_number</span>, <span class="prelude-val">Some</span>(<span class="number">5</span>));</pre></div>
|
||
|
</div><h3 id='method.any' class='method'><code id='any.v'>fn <a href='#method.any' class='fnname'>any</a><P>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Searches for <strong>some</strong> item in the parallel iterator that
|
||
|
matches the given predicate, and if so returns true. Once
|
||
|
a match is found, we'll attempt to stop process the rest
|
||
|
of the items. Proving that there's no match, returning false,
|
||
|
does require visiting every item.</p>
|
||
|
<h1 id="examples-38" class="section-header"><a href="#examples-38">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">12</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">23</span>, <span class="number">0</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">is_valid</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">any</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">></span> <span class="number">10</span>);
|
||
|
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">is_valid</span>);</pre></div>
|
||
|
</div><h3 id='method.all' class='method'><code id='all.v'>fn <a href='#method.all' class='fnname'>all</a><P>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> <span class="where fmt-newline">where<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Tests that every item in the parallel iterator matches the given
|
||
|
predicate, and if so returns true. If a counter-example is found,
|
||
|
we'll attempt to stop processing more items, then return false.</p>
|
||
|
<h1 id="examples-39" class="section-header"><a href="#examples-39">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [<span class="number">0</span>, <span class="number">12</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">0</span>, <span class="number">23</span>, <span class="number">0</span>];
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">is_valid</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">all</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">></span> <span class="number">10</span>);
|
||
|
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">is_valid</span>);</pre></div>
|
||
|
</div><h3 id='method.while_some' class='method'><code id='while_some.v'>fn <a href='#method.while_some' class='fnname'>while_some</a><T>(self) -> <a class="struct" href="../../rayon/iter/struct.WhileSome.html" title="struct rayon::iter::WhileSome">WhileSome</a><Self> <span class="where fmt-newline">where<br> Self: <a class="trait" href="../../rayon/iter/trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a><Item = <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><T>>,<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Creates an iterator over the <code>Some</code> items of this iterator, halting
|
||
|
as soon as any <code>None</code> is found.</p>
|
||
|
<h1 id="examples-40" class="section-header"><a href="#examples-40">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">sync</span>::<span class="ident">atomic</span>::{<span class="ident">AtomicUsize</span>, <span class="ident">Ordering</span>};
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">counter</span> <span class="op">=</span> <span class="ident">AtomicUsize</span>::<span class="ident">new</span>(<span class="number">0</span>);
|
||
|
<span class="kw">let</span> <span class="ident">value</span> <span class="op">=</span> (<span class="number">0_i32</span>..<span class="number">2048</span>)
|
||
|
.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> {
|
||
|
<span class="ident">counter</span>.<span class="ident">fetch_add</span>(<span class="number">1</span>, <span class="ident">Ordering</span>::<span class="ident">SeqCst</span>);
|
||
|
<span class="kw">if</span> <span class="ident">x</span> <span class="op"><</span> <span class="number">1024</span> { <span class="prelude-val">Some</span>(<span class="ident">x</span>) } <span class="kw">else</span> { <span class="prelude-val">None</span> }
|
||
|
})
|
||
|
.<span class="ident">while_some</span>()
|
||
|
.<span class="ident">max</span>();
|
||
|
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">value</span> <span class="op"><</span> <span class="prelude-val">Some</span>(<span class="number">1024</span>));
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">counter</span>.<span class="ident">load</span>(<span class="ident">Ordering</span>::<span class="ident">SeqCst</span>) <span class="op"><</span> <span class="number">2048</span>); <span class="comment">// should not have visited every single one</span></pre></div>
|
||
|
</div><h3 id='method.panic_fuse' class='method'><code id='panic_fuse.v'>fn <a href='#method.panic_fuse' class='fnname'>panic_fuse</a>(self) -> <a class="struct" href="../../rayon/iter/struct.PanicFuse.html" title="struct rayon::iter::PanicFuse">PanicFuse</a><Self></code></h3><div class='docblock'><p>Wraps an iterator with a fuse in case of panics, to halt all threads
|
||
|
as soon as possible.</p>
|
||
|
<p>Panics within parallel iterators are always propagated to the caller,
|
||
|
but they don't always halt the rest of the iterator right away, due to
|
||
|
the internal semantics of <a href="../fn.join.html#panics"><code>join</code></a>. This adaptor makes a greater effort
|
||
|
to stop processing other items sooner, with the cost of additional
|
||
|
synchronization overhead, which may also inhibit some optimizations.</p>
|
||
|
<h1 id="examples-41" class="section-header"><a href="#examples-41">Examples</a></h1>
|
||
|
<p>If this code didn't use <code>panic_fuse()</code>, it would continue processing
|
||
|
many more items in other threads (with long sleep delays) before the
|
||
|
panic is finally propagated.</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">use</span> <span class="ident">std</span>::{<span class="ident">thread</span>, <span class="ident">time</span>};
|
||
|
|
||
|
(<span class="number">0</span>..<span class="number">1_000_000</span>)
|
||
|
.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">panic_fuse</span>()
|
||
|
.<span class="ident">for_each</span>(<span class="op">|</span><span class="ident">i</span><span class="op">|</span> {
|
||
|
<span class="comment">// simulate some work</span>
|
||
|
<span class="ident">thread</span>::<span class="ident">sleep</span>(<span class="ident">time</span>::<span class="ident">Duration</span>::<span class="ident">from_secs</span>(<span class="number">1</span>));
|
||
|
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">i</span> <span class="op">></span> <span class="number">0</span>); <span class="comment">// oops!</span>
|
||
|
});</pre></div>
|
||
|
</div><h3 id='method.collect' class='method'><code id='collect.v'>fn <a href='#method.collect' class='fnname'>collect</a><C>(self) -> C <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/trait.FromParallelIterator.html" title="trait rayon::iter::FromParallelIterator">FromParallelIterator</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code></h3><div class='docblock'><p>Create a fresh collection containing all the element produced
|
||
|
by this parallel iterator.</p>
|
||
|
<p>You may prefer to use <code>collect_into_vec()</code>, which allocates more
|
||
|
efficiently with precise knowledge of how many elements the
|
||
|
iterator contains, and even allows you to reuse an existing
|
||
|
vector's backing store rather than allocating a fresh vector.</p>
|
||
|
<h1 id="examples-42" class="section-header"><a href="#examples-42">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">sync_vec</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">100</span>).<span class="ident">into_iter</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">async_vec</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">100</span>).<span class="ident">into_par_iter</span>().<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">sync_vec</span>, <span class="ident">async_vec</span>);</pre></div>
|
||
|
</div><h3 id='method.unzip' class='method'><code id='unzip.v'>fn <a href='#method.unzip' class='fnname'>unzip</a><A, B, FromA, FromB>(self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>FromA, FromB<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> Self: <a class="trait" href="../../rayon/iter/trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a><Item = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>A, B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a>>,<br> FromA: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><A>,<br> FromB: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><B>,<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Unzips the items of a parallel iterator into a pair of arbitrary
|
||
|
<code>ParallelExtend</code> containers.</p>
|
||
|
<p>You may prefer to use <code>unzip_into_vecs()</code>, which allocates more
|
||
|
efficiently with precise knowledge of how many elements the
|
||
|
iterator contains, and even allows you to reuse existing
|
||
|
vectors' backing stores rather than allocating fresh vectors.</p>
|
||
|
<h1 id="examples-43" class="section-header"><a href="#examples-43">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">a</span> <span class="op">=</span> [(<span class="number">0</span>, <span class="number">1</span>), (<span class="number">1</span>, <span class="number">2</span>), (<span class="number">2</span>, <span class="number">3</span>), (<span class="number">3</span>, <span class="number">4</span>)];
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>): (<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>) <span class="op">=</span> <span class="ident">a</span>.<span class="ident">par_iter</span>().<span class="ident">cloned</span>().<span class="ident">unzip</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">left</span>, [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">right</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);</pre></div>
|
||
|
<p>Nested pairs can be unzipped too.</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">values</span>, (<span class="ident">squares</span>, <span class="ident">cubes</span>)): (<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, (<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>)) <span class="op">=</span> (<span class="number">0</span>..<span class="number">4</span>).<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">map</span>(<span class="op">|</span><span class="ident">i</span><span class="op">|</span> (<span class="ident">i</span>, (<span class="ident">i</span> <span class="op">*</span> <span class="ident">i</span>, <span class="ident">i</span> <span class="op">*</span> <span class="ident">i</span> <span class="op">*</span> <span class="ident">i</span>)))
|
||
|
.<span class="ident">unzip</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">values</span>, [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">squares</span>, [<span class="number">0</span>, <span class="number">1</span>, <span class="number">4</span>, <span class="number">9</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">cubes</span>, [<span class="number">0</span>, <span class="number">1</span>, <span class="number">8</span>, <span class="number">27</span>]);</pre></div>
|
||
|
</div><h3 id='method.partition' class='method'><code id='partition.v'>fn <a href='#method.partition' class='fnname'>partition</a><A, B, P>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>A, B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>,<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Partitions the items of a parallel iterator into a pair of arbitrary
|
||
|
<code>ParallelExtend</code> containers. Items for which the <code>predicate</code> returns
|
||
|
true go into the first container, and the rest go into the second.</p>
|
||
|
<p>Note: unlike the standard <code>Iterator::partition</code>, this allows distinct
|
||
|
collection types for the left and right items. This is more flexible,
|
||
|
but may require new type annotations when converting sequential code
|
||
|
that used type inferrence assuming the two were the same.</p>
|
||
|
<h1 id="examples-44" class="section-header"><a href="#examples-44">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>): (<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>) <span class="op">=</span> (<span class="number">0</span>..<span class="number">8</span>).<span class="ident">into_par_iter</span>().<span class="ident">partition</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>);
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">left</span>, [<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">right</span>, [<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>]);</pre></div>
|
||
|
</div><h3 id='method.partition_map' class='method'><code id='partition_map.v'>fn <a href='#method.partition_map' class='fnname'>partition_map</a><A, B, P, L, R>(self, predicate: P) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a>A, B<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a> <span class="where fmt-newline">where<br> A: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><L>,<br> B: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="../../rayon/iter/trait.ParallelExtend.html" title="trait rayon::iter::ParallelExtend">ParallelExtend</a><R>,<br> P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="enum" href="../../rayon/iter/enum.Either.html" title="enum rayon::iter::Either">Either</a><L, R> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> L: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code></h3><div class='docblock'><p>Partitions and maps the items of a parallel iterator into a pair of
|
||
|
arbitrary <code>ParallelExtend</code> containers. <code>Either::Left</code> items go into
|
||
|
the first container, and <code>Either::Right</code> items go into the second.</p>
|
||
|
<h1 id="examples-45" class="section-header"><a href="#examples-45">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">iter</span>::<span class="ident">Either</span>;
|
||
|
|
||
|
<span class="kw">let</span> (<span class="ident">left</span>, <span class="ident">right</span>): (<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>) <span class="op">=</span> (<span class="number">0</span>..<span class="number">8</span>).<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">partition_map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> {
|
||
|
<span class="kw">if</span> <span class="ident">x</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span> {
|
||
|
<span class="ident">Either</span>::<span class="ident">Left</span>(<span class="ident">x</span> <span class="op">*</span> <span class="number">4</span>)
|
||
|
} <span class="kw">else</span> {
|
||
|
<span class="ident">Either</span>::<span class="ident">Right</span>(<span class="ident">x</span> <span class="op">*</span> <span class="number">3</span>)
|
||
|
}
|
||
|
});
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">left</span>, [<span class="number">0</span>, <span class="number">8</span>, <span class="number">16</span>, <span class="number">24</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">right</span>, [<span class="number">3</span>, <span class="number">9</span>, <span class="number">15</span>, <span class="number">21</span>]);</pre></div>
|
||
|
<p>Nested <code>Either</code> enums can be split as well.</p>
|
||
|
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">iter</span>::<span class="ident">Either</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> ((<span class="ident">fizzbuzz</span>, <span class="ident">fizz</span>), (<span class="ident">buzz</span>, <span class="ident">other</span>)): ((<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>), (<span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>, <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span>)) <span class="op">=</span> (<span class="number">1</span>..<span class="number">20</span>)
|
||
|
.<span class="ident">into_par_iter</span>()
|
||
|
.<span class="ident">partition_map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> <span class="kw">match</span> (<span class="ident">x</span> <span class="op">%</span> <span class="number">3</span>, <span class="ident">x</span> <span class="op">%</span> <span class="number">5</span>) {
|
||
|
(<span class="number">0</span>, <span class="number">0</span>) <span class="op">=</span><span class="op">></span> <span class="ident">Left</span>(<span class="ident">Left</span>(<span class="ident">x</span>)),
|
||
|
(<span class="number">0</span>, <span class="kw">_</span>) <span class="op">=</span><span class="op">></span> <span class="ident">Left</span>(<span class="ident">Right</span>(<span class="ident">x</span>)),
|
||
|
(<span class="kw">_</span>, <span class="number">0</span>) <span class="op">=</span><span class="op">></span> <span class="ident">Right</span>(<span class="ident">Left</span>(<span class="ident">x</span>)),
|
||
|
(<span class="kw">_</span>, <span class="kw">_</span>) <span class="op">=</span><span class="op">></span> <span class="ident">Right</span>(<span class="ident">Right</span>(<span class="ident">x</span>)),
|
||
|
});
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">fizzbuzz</span>, [<span class="number">15</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">fizz</span>, [<span class="number">3</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">12</span>, <span class="number">18</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">buzz</span>, [<span class="number">5</span>, <span class="number">10</span>]);
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">other</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">11</span>, <span class="number">13</span>, <span class="number">14</span>, <span class="number">16</span>, <span class="number">17</span>, <span class="number">19</span>]);</pre></div>
|
||
|
</div><h3 id='method.intersperse' class='method'><code id='intersperse.v'>fn <a href='#method.intersperse' class='fnname'>intersperse</a>(self, element: Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>) -> <a class="struct" href="../../rayon/iter/struct.Intersperse.html" title="struct rayon::iter::Intersperse">Intersperse</a><Self> <span class="where fmt-newline">where<br> Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></code></h3><div class='docblock'><p>Intersperses clones of an element between items of this iterator.</p>
|
||
|
<h1 id="examples-46" class="section-header"><a href="#examples-46">Examples</a></h1>
|
||
|
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
|
<span class="kw">use</span> <span class="ident">rayon</span>::<span class="ident">prelude</span>::<span class="kw-2">*</span>;
|
||
|
|
||
|
<span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];
|
||
|
<span class="kw">let</span> <span class="ident">r</span>: <span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span> <span class="op">=</span> <span class="ident">x</span>.<span class="ident">into_par_iter</span>().<span class="ident">intersperse</span>(<span class="op">-</span><span class="number">1</span>).<span class="ident">collect</span>();
|
||
|
|
||
|
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">r</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="op">-</span><span class="number">1</span>, <span class="number">2</span>, <span class="op">-</span><span class="number">1</span>, <span class="number">3</span>]);</pre></div>
|
||
|
</div><h3 id='method.opt_len' class='method'><code id='opt_len.v'>fn <a href='#method.opt_len' class='fnname'>opt_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></code></h3><div class='docblock'><p>Internal method used to define the behavior of this parallel
|
||
|
iterator. You should not need to call this directly.</p>
|
||
|
<p>Returns the number of items produced by this iterator, if known
|
||
|
statically. This can be used by consumers to trigger special fast
|
||
|
paths. Therefore, if <code>Some(_)</code> is returned, this iterator must only
|
||
|
use the (indexed) <code>Consumer</code> methods when driving a consumer, such
|
||
|
as <code>split_at()</code>. Calling <code>UnindexedConsumer::split_off_left()</code> or
|
||
|
other <code>UnindexedConsumer</code> methods -- or returning an inaccurate
|
||
|
value -- may result in panics.</p>
|
||
|
<p>This method is currently used to optimize <code>collect</code> for want
|
||
|
of true Rust specialization; it may be removed when
|
||
|
specialization is stable.</p>
|
||
|
</div></div><span class='loading-content'>Loading content...</span>
|
||
|
<h2 id='implementors' class='small-section-header'>Implementors<a href='#implementors' class='anchor'></a></h2><div class='item-list' id='implementors-list'><h3 id='impl-ParallelIterator' class='impl'><code class='in-band'>impl ParallelIterator for rayon::range::<a class="struct" href="../../rayon/range/struct.Iter.html" title="struct rayon::range::Iter">Iter</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i128.html">i128</a>></code><a href='#impl-ParallelIterator' class='anchor'></a><a class='srclink' href='../../src/rayon/range.rs.html#152-178' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-1' class="type"><code id='Item.t-1'>type <a href='#associatedtype.Item-1' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i128.html">i128</a></code></h4><h4 id='method.drive_unindexed' class="method hidden"><code id='drive_unindexed.v-1'>fn <a href='#method.drive_unindexed' class='fnname'>drive_unindexed</a><C>(self, consumer: C) -> C::<a class="type" href="../../rayon/iter/plumbing/trait.Consumer.html#associatedtype.Result" title="type rayon::iter::plumbing::Consumer::Result">Result</a> <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/plumbing/trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">UnindexedConsumer</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code><a class='srclink' href='../../src/rayon/range.rs.html#155-168' title='goto source code'>[src]</a></h4><h4 id='method.opt_len-1' class="method hidden"><code id='opt_len.v-1'>fn <a href='#method.opt_len-1' class='fnname'>opt_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></code><a class='srclink' href='../../src/rayon/range.rs.html#170-177' title='goto source code'>[src]</a></h4></div><h3 id='impl-ParallelIterator-1' class='impl'><code class='in-band'>impl ParallelIterator for rayon::range::<a class="struct" href="../../rayon/range/struct.Iter.html" title="struct rayon::range::Iter">Iter</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>></code><a href='#impl-ParallelIterator-1' class='anchor'></a><a class='srclink' href='../../src/rayon/range.rs.html#80-93' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-2' class="type"><code id='Item.t-2'>type <a href='#associatedtype.Item-2' class="type">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a></code></h4><h4 id='method.drive_unindexed-1' class="method hidden"><code id='drive_unindexed.v-2'>fn <a href='#method.drive_unindexed-1' class='fnname'>drive_unindexed</a><C>(self, consumer: C) -> C::<a class="type" href="../../rayon/iter/plumbing/trait.Consumer.html#associatedtype.Result" title="type rayon::iter::plumbing::Consumer::Result">Result</a> <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/plumbing/trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">UnindexedConsumer</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code><a class='srclink' href='../../src/rayon/range.rs.html#83-88' title='goto source code'>[src]</a></h4><h4 id='method.opt_len-2' class="method hidden"><code id='opt_len.v-2'>fn <a href='#method.opt_len-2' class='fnname'>opt_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option
|
||
|
</div><div class='impl-items'><h4 id='associatedtype.Item-86' class="type"><code id='Item.t-86'>type <a href='#associatedtype.Item-86' class="type">Item</a> = L::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a></code></h4><h4 id='method.drive_unindexed-85' class="method hidden"><code id='drive_unindexed.v-86'>fn <a href='#method.drive_unindexed-85' class='fnname'>drive_unindexed</a><C>(self, consumer: C) -> C::<a class="type" href="../../rayon/iter/plumbing/trait.Consumer.html#associatedtype.Result" title="type rayon::iter::plumbing::Consumer::Result">Result</a> <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/plumbing/trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">UnindexedConsumer</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code><a class='srclink' href='../../src/rayon/par_either.rs.html#13-21' title='goto source code'>[src]</a></h4><h4 id='method.opt_len-67' class="method hidden"><code id='opt_len.v-67'>fn <a href='#method.opt_len-67' class='fnname'>opt_len</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>></code><a class='srclink' href='../../src/rayon/par_either.rs.html#23-25' title='goto source code'>[src]</a></h4></div><h3 id='impl-ParallelIterator-86' class='impl'><code class='in-band'>impl<T> ParallelIterator for <a class="struct" href="../../rayon/iter/struct.Repeat.html" title="struct rayon::iter::Repeat">Repeat</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code><a href='#impl-ParallelIterator-86' class='anchor'></a><a class='srclink' href='../../src/rayon/iter/repeat.rs.html#57-72' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-87' class="type"><code id='Item.t-87'>type <a href='#associatedtype.Item-87' class="type">Item</a> = T</code></h4><h4 id='method.drive_unindexed-86' class="method hidden"><code id='drive_unindexed.v-87'>fn <a href='#method.drive_unindexed-86' class='fnname'>drive_unindexed</a><C>(self, consumer: C) -> C::<a class="type" href="../../rayon/iter/plumbing/trait.Consumer.html#associatedtype.Result" title="type rayon::iter::plumbing::Consumer::Result">Result</a> <span class="where fmt-newline">where<br> C: <a class="trait" href="../../rayon/iter/plumbing/trait.UnindexedConsumer.html" title="trait rayon::iter::plumbing::UnindexedConsumer">UnindexedConsumer</a><Self::<a class="type" href="../../rayon/iter/trait.ParallelIterator.html#associatedtype.Item" title="type rayon::iter::ParallelIterator::Item">Item</a>>, </span></code><a class='srclink' href='../../src/rayon/iter/repeat.rs.html#63-71' title='goto source code'>[src]</a></h4></div><h3 id='impl-ParallelIterator-87' class='impl'><code class='in-band'>impl<T> ParallelIterator for <a class="struct" href="../../rayon/iter/struct.RepeatN.html" title="struct rayon::iter::RepeatN">RepeatN</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code><a href='#impl-ParallelIterator-87' class='anchor'></a><a class='srclink
|
||
|
src="../../implementors/rayon/iter/trait.ParallelIterator.js">
|
||
|
</script></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "rayon";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
|