Files
GopherGate/target/doc/rayon/iter/trait.ParallelDrainRange.html
2026-02-26 12:00:21 -05:00

65 lines
20 KiB
HTML

<!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="`ParallelDrainRange` creates a parallel iterator that moves a range of items from a collection while retaining the original capacity."><title>ParallelDrainRange in rayon::iter - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="rayon" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">ParallelDrainRange</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../rayon/index.html">rayon</a><span class="version">1.11.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Parallel<wbr>Drain<wbr>Range</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Item" title="Item">Item</a></li><li><a href="#associatedtype.Iter" title="Iter">Iter</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.par_drain" title="par_drain">par_drain</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-ParallelDrainRange-for-%26mut+String" title="&#38;&#39;a mut String">&#38;&#39;a mut String</a></li><li><a href="#impl-ParallelDrainRange-for-%26mut+VecDeque%3CT%3E" title="&#38;&#39;a mut VecDeque&#60;T&#62;">&#38;&#39;a mut VecDeque&#60;T&#62;</a></li><li><a href="#impl-ParallelDrainRange-for-%26mut+Vec%3CT%3E" title="&#38;&#39;data mut Vec&#60;T&#62;">&#38;&#39;data mut Vec&#60;T&#62;</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In rayon::<wbr>iter</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">rayon</a>::<wbr><a href="index.html">iter</a></div><h1>Trait <span class="trait">Parallel<wbr>Drain<wbr>Range</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/rayon/iter/mod.rs.html#3400-3467">Source</a> </span></div><pre class="rust item-decl"><code>pub trait ParallelDrainRange&lt;Idx = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>&gt; {
type <a href="#associatedtype.Iter" class="associatedtype">Iter</a>: <a class="trait" href="trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a>&lt;Item = Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Item" title="type rayon::iter::ParallelDrainRange::Item">Item</a>&gt;;
type <a href="#associatedtype.Item" class="associatedtype">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>;
// Required method
fn <a href="#tymethod.par_drain" class="fn">par_drain</a>&lt;R: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a>&lt;Idx&gt;&gt;(self, range: R) -&gt; Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Iter" title="type rayon::iter::ParallelDrainRange::Iter">Iter</a>;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>ParallelDrainRange</code> creates a parallel iterator that moves a range of items
from a collection while retaining the original capacity.</p>
<p>Types which are not indexable may implement <a href="trait.ParallelDrainFull.html" title="trait rayon::iter::ParallelDrainFull"><code>ParallelDrainFull</code></a> instead.</p>
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Iter" class="method"><a class="src rightside" href="../../src/rayon/iter/mod.rs.html#3402">Source</a><h4 class="code-header">type <a href="#associatedtype.Iter" class="associatedtype">Iter</a>: <a class="trait" href="trait.ParallelIterator.html" title="trait rayon::iter::ParallelIterator">ParallelIterator</a>&lt;Item = Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Item" title="type rayon::iter::ParallelDrainRange::Item">Item</a>&gt;</h4></section></summary><div class="docblock"><p>The draining parallel iterator type that will be created.</p>
</div></details><details class="toggle" open><summary><section id="associatedtype.Item" class="method"><a class="src rightside" href="../../src/rayon/iter/mod.rs.html#3406">Source</a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a>: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a></h4></section></summary><div class="docblock"><p>The type of item that the parallel iterator will produce.
This is usually the same as <code>IntoParallelIterator::Item</code>.</p>
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.par_drain" class="method"><a class="src rightside" href="../../src/rayon/iter/mod.rs.html#3466">Source</a><h4 class="code-header">fn <a href="#tymethod.par_drain" class="fn">par_drain</a>&lt;R: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a>&lt;Idx&gt;&gt;(self, range: R) -&gt; Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Iter" title="type rayon::iter::ParallelDrainRange::Iter">Iter</a></h4></section></summary><div class="docblock"><p>Returns a draining parallel iterator over a range of the collection.</p>
<p>When the iterator is dropped, all items in the range are removed, even
if the iterator was not fully consumed. If the iterator is leaked, for
example using <code>std::mem::forget</code>, it is unspecified how many items are
removed.</p>
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rayon::prelude::<span class="kw-2">*</span>;
<span class="kw">let </span>squares: Vec&lt;i32&gt; = (<span class="number">0</span>..<span class="number">10</span>).map(|x| x * x).collect();
<span class="macro">println!</span>(<span class="string">"RangeFull"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>vec = squares.clone();
<span class="macro">assert!</span>(vec.par_drain(..)
.eq(squares.par_iter().copied()));
<span class="macro">assert!</span>(vec.is_empty());
<span class="macro">assert!</span>(vec.capacity() &gt;= squares.len());
<span class="macro">println!</span>(<span class="string">"RangeFrom"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>vec = squares.clone();
<span class="macro">assert!</span>(vec.par_drain(<span class="number">5</span>..)
.eq(squares[<span class="number">5</span>..].par_iter().copied()));
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[..], <span class="kw-2">&amp;</span>squares[..<span class="number">5</span>]);
<span class="macro">assert!</span>(vec.capacity() &gt;= squares.len());
<span class="macro">println!</span>(<span class="string">"RangeTo"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>vec = squares.clone();
<span class="macro">assert!</span>(vec.par_drain(..<span class="number">5</span>)
.eq(squares[..<span class="number">5</span>].par_iter().copied()));
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[..], <span class="kw-2">&amp;</span>squares[<span class="number">5</span>..]);
<span class="macro">assert!</span>(vec.capacity() &gt;= squares.len());
<span class="macro">println!</span>(<span class="string">"RangeToInclusive"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>vec = squares.clone();
<span class="macro">assert!</span>(vec.par_drain(..=<span class="number">5</span>)
.eq(squares[..=<span class="number">5</span>].par_iter().copied()));
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[..], <span class="kw-2">&amp;</span>squares[<span class="number">6</span>..]);
<span class="macro">assert!</span>(vec.capacity() &gt;= squares.len());
<span class="macro">println!</span>(<span class="string">"Range"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>vec = squares.clone();
<span class="macro">assert!</span>(vec.par_drain(<span class="number">3</span>..<span class="number">7</span>)
.eq(squares[<span class="number">3</span>..<span class="number">7</span>].par_iter().copied()));
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[..<span class="number">3</span>], <span class="kw-2">&amp;</span>squares[..<span class="number">3</span>]);
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[<span class="number">3</span>..], <span class="kw-2">&amp;</span>squares[<span class="number">7</span>..]);
<span class="macro">assert!</span>(vec.capacity() &gt;= squares.len());
<span class="macro">println!</span>(<span class="string">"RangeInclusive"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>vec = squares.clone();
<span class="macro">assert!</span>(vec.par_drain(<span class="number">3</span>..=<span class="number">7</span>)
.eq(squares[<span class="number">3</span>..=<span class="number">7</span>].par_iter().copied()));
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[..<span class="number">3</span>], <span class="kw-2">&amp;</span>squares[..<span class="number">3</span>]);
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>vec[<span class="number">3</span>..], <span class="kw-2">&amp;</span>squares[<span class="number">8</span>..]);
<span class="macro">assert!</span>(vec.capacity() &gt;= squares.len());</code></pre></div></div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.93.1/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-ParallelDrainRange-for-%26mut+String" class="impl"><a class="src rightside" href="../../src/rayon/string.rs.html#10-20">Source</a><a href="#impl-ParallelDrainRange-for-%26mut+String" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.ParallelDrainRange.html" title="trait rayon::iter::ParallelDrainRange">ParallelDrainRange</a> for &amp;'a mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Iter-1" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rayon/string.rs.html#11">Source</a><a href="#associatedtype.Iter-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Iter" class="associatedtype">Iter</a> = <a class="struct" href="../string/struct.Drain.html" title="struct rayon::string::Drain">Drain</a>&lt;'a&gt;</h4></section><section id="associatedtype.Item-1" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rayon/string.rs.html#12">Source</a><a href="#associatedtype.Item-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a> = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.char.html">char</a></h4></section><section id="method.par_drain" class="method trait-impl"><a class="src rightside" href="../../src/rayon/string.rs.html#14-19">Source</a><a href="#method.par_drain" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.par_drain" class="fn">par_drain</a>&lt;R: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>&gt;&gt;(self, range: R) -&gt; Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Iter" title="type rayon::iter::ParallelDrainRange::Iter">Iter</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ParallelDrainRange-for-%26mut+VecDeque%3CT%3E" class="impl"><a class="src rightside" href="../../src/rayon/collections/vec_deque.rs.html#100-111">Source</a><a href="#impl-ParallelDrainRange-for-%26mut+VecDeque%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a, T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt; <a class="trait" href="trait.ParallelDrainRange.html" title="trait rayon::iter::ParallelDrainRange">ParallelDrainRange</a> for &amp;'a mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/collections/vec_deque/struct.VecDeque.html" title="struct alloc::collections::vec_deque::VecDeque">VecDeque</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="associatedtype.Iter-2" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rayon/collections/vec_deque.rs.html#101">Source</a><a href="#associatedtype.Iter-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Iter" class="associatedtype">Iter</a> = <a class="struct" href="../collections/vec_deque/struct.Drain.html" title="struct rayon::collections::vec_deque::Drain">Drain</a>&lt;'a, T&gt;</h4></section><section id="associatedtype.Item-2" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rayon/collections/vec_deque.rs.html#102">Source</a><a href="#associatedtype.Item-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a> = T</h4></section><section id="method.par_drain-1" class="method trait-impl"><a class="src rightside" href="../../src/rayon/collections/vec_deque.rs.html#104-110">Source</a><a href="#method.par_drain-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.par_drain" class="fn">par_drain</a>&lt;R: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>&gt;&gt;(self, range: R) -&gt; Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Iter" title="type rayon::iter::ParallelDrainRange::Iter">Iter</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ParallelDrainRange-for-%26mut+Vec%3CT%3E" class="impl"><a class="src rightside" href="../../src/rayon/vec.rs.html#96-107">Source</a><a href="#impl-ParallelDrainRange-for-%26mut+Vec%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'data, T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt; <a class="trait" href="trait.ParallelDrainRange.html" title="trait rayon::iter::ParallelDrainRange">ParallelDrainRange</a> for &amp;'data mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="associatedtype.Iter-3" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rayon/vec.rs.html#97">Source</a><a href="#associatedtype.Iter-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Iter" class="associatedtype">Iter</a> = <a class="struct" href="../vec/struct.Drain.html" title="struct rayon::vec::Drain">Drain</a>&lt;'data, T&gt;</h4></section><section id="associatedtype.Item-3" class="associatedtype trait-impl"><a class="src rightside" href="../../src/rayon/vec.rs.html#98">Source</a><a href="#associatedtype.Item-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Item" class="associatedtype">Item</a> = T</h4></section><section id="method.par_drain-2" class="method trait-impl"><a class="src rightside" href="../../src/rayon/vec.rs.html#100-106">Source</a><a href="#method.par_drain-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.par_drain" class="fn">par_drain</a>&lt;R: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/range/trait.RangeBounds.html" title="trait core::ops::range::RangeBounds">RangeBounds</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.usize.html">usize</a>&gt;&gt;(self, range: R) -&gt; Self::<a class="associatedtype" href="trait.ParallelDrainRange.html#associatedtype.Iter" title="type rayon::iter::ParallelDrainRange::Iter">Iter</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../../trait.impl/rayon/iter/trait.ParallelDrainRange.js" data-ignore-extern-crates="alloc" async></script></section></div></main></body></html>