| <!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="Parallel extensions for strings."><meta name="keywords" content="rust, rustlang, rust-lang, ParallelString"><title>ParallelString in rayon::str - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../../rayon/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../rayon/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">ParallelString</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.as_parallel_string">as_parallel_string</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.par_bytes">par_bytes</a></li><li><a href="#method.par_char_indices">par_char_indices</a></li><li><a href="#method.par_chars">par_chars</a></li><li><a href="#method.par_encode_utf16">par_encode_utf16</a></li><li><a href="#method.par_lines">par_lines</a></li><li><a href="#method.par_match_indices">par_match_indices</a></li><li><a href="#method.par_matches">par_matches</a></li><li><a href="#method.par_split">par_split</a></li><li><a href="#method.par_split_terminator">par_split_terminator</a></li><li><a href="#method.par_split_whitespace">par_split_whitespace</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-ParallelString-for-str">str</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In rayon::str</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../index.html">rayon</a>::<wbr><a href="index.html">str</a>::<wbr><a class="trait" href="#">ParallelString</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/rayon/str.rs.html#60-266">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait ParallelString { |
| fn <a href="#tymethod.as_parallel_string" class="fnname">as_parallel_string</a>(&self) -> &str; |
| |
| fn <a href="#method.par_chars" class="fnname">par_chars</a>(&self) -> <a class="struct" href="struct.Chars.html" title="struct rayon::str::Chars">Chars</a><'_> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_char_indices" class="fnname">par_char_indices</a>(&self) -> <a class="struct" href="struct.CharIndices.html" title="struct rayon::str::CharIndices">CharIndices</a><'_> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_bytes" class="fnname">par_bytes</a>(&self) -> <a class="struct" href="struct.Bytes.html" title="struct rayon::str::Bytes">Bytes</a><'_> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_encode_utf16" class="fnname">par_encode_utf16</a>(&self) -> <a class="struct" href="struct.EncodeUtf16.html" title="struct rayon::str::EncodeUtf16">EncodeUtf16</a><'_> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_split" class="fnname">par_split</a><P: Pattern>(&self, separator: P) -> <a class="struct" href="struct.Split.html" title="struct rayon::str::Split">Split</a><'_, P> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_split_terminator" class="fnname">par_split_terminator</a><P: Pattern>(<br> &self,<br> terminator: P<br> ) -> <a class="struct" href="struct.SplitTerminator.html" title="struct rayon::str::SplitTerminator">SplitTerminator</a><'_, P> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_lines" class="fnname">par_lines</a>(&self) -> <a class="struct" href="struct.Lines.html" title="struct rayon::str::Lines">Lines</a><'_> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_split_whitespace" class="fnname">par_split_whitespace</a>(&self) -> <a class="struct" href="struct.SplitWhitespace.html" title="struct rayon::str::SplitWhitespace">SplitWhitespace</a><'_> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_matches" class="fnname">par_matches</a><P: Pattern>(&self, pattern: P) -> <a class="struct" href="struct.Matches.html" title="struct rayon::str::Matches">Matches</a><'_, P> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.par_match_indices" class="fnname">par_match_indices</a><P: Pattern>(&self, pattern: P) -> <a class="struct" href="struct.MatchIndices.html" title="struct rayon::str::MatchIndices">MatchIndices</a><'_, P> { ... } |
| }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Parallel extensions for strings.</p> |
| </div></details><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.as_parallel_string" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#63">source</a><h4 class="code-header">fn <a href="#tymethod.as_parallel_string" class="fnname">as_parallel_string</a>(&self) -> &str</h4></section></summary><div class="docblock"><p>Returns a plain string slice, which is used to implement the rest of |
| the parallel methods.</p> |
| </div></details></div><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_chars" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#74-78">source</a><h4 class="code-header">fn <a href="#method.par_chars" class="fnname">par_chars</a>(&self) -> <a class="struct" href="struct.Chars.html" title="struct rayon::str::Chars">Chars</a><'_></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over the characters of a string.</p> |
| <h5 id="examples"><a href="#examples">Examples</a></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>max = <span class="string">"hello"</span>.par_chars().max_by_key(|c| <span class="kw-2">*</span>c <span class="kw">as </span>i32); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">'o'</span>), max);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_char_indices" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#89-93">source</a><h4 class="code-header">fn <a href="#method.par_char_indices" class="fnname">par_char_indices</a>(&self) -> <a class="struct" href="struct.CharIndices.html" title="struct rayon::str::CharIndices">CharIndices</a><'_></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over the characters of a string, with their positions.</p> |
| <h5 id="examples-1"><a href="#examples-1">Examples</a></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>min = <span class="string">"hello"</span>.par_char_indices().min_by_key(|<span class="kw-2">&</span>(_i, c)| c <span class="kw">as </span>i32); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">'e'</span>)), min);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_bytes" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#109-113">source</a><h4 class="code-header">fn <a href="#method.par_bytes" class="fnname">par_bytes</a>(&self) -> <a class="struct" href="struct.Bytes.html" title="struct rayon::str::Bytes">Bytes</a><'_></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over the bytes of a string.</p> |
| <p>Note that multi-byte sequences (for code points greater than <code>U+007F</code>) |
| are produced as separate items, but will not be split across threads. |
| If you would prefer an indexed iterator without that guarantee, consider |
| <code>string.as_bytes().par_iter().copied()</code> instead.</p> |
| <h5 id="examples-2"><a href="#examples-2">Examples</a></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>max = <span class="string">"hello"</span>.par_bytes().max(); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">b'o'</span>), max);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_encode_utf16" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#133-137">source</a><h4 class="code-header">fn <a href="#method.par_encode_utf16" class="fnname">par_encode_utf16</a>(&self) -> <a class="struct" href="struct.EncodeUtf16.html" title="struct rayon::str::EncodeUtf16">EncodeUtf16</a><'_></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over a string encoded as UTF-16.</p> |
| <p>Note that surrogate pairs (for code points greater than <code>U+FFFF</code>) are |
| produced as separate items, but will not be split across threads.</p> |
| <h5 id="examples-3"><a href="#examples-3">Examples</a></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>max = <span class="string">"hello"</span>.par_encode_utf16().max(); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">b'o' </span><span class="kw">as </span>u16), max); |
| |
| <span class="kw">let </span>text = <span class="string">"Zażółć gęślą jaźń"</span>; |
| <span class="kw">let </span>utf8_len = text.len(); |
| <span class="kw">let </span>utf16_len = text.par_encode_utf16().count(); |
| <span class="macro">assert!</span>(utf16_len <= utf8_len);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_split" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#156-158">source</a><h4 class="code-header">fn <a href="#method.par_split" class="fnname">par_split</a><P: Pattern>(&self, separator: P) -> <a class="struct" href="struct.Split.html" title="struct rayon::str::Split">Split</a><'_, P></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over substrings separated by a |
| given character or predicate, similar to <code>str::split</code>.</p> |
| <p>Note: the <code>Pattern</code> trait is private, for use only by Rayon itself. |
| It is implemented for <code>char</code>, <code>&[char]</code>, and any function or closure |
| <code>F: Fn(char) -> bool + Sync + Send</code>.</p> |
| <h5 id="examples-4"><a href="#examples-4">Examples</a></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>total = <span class="string">"1, 2, buckle, 3, 4, door" |
| </span>.par_split(<span class="string">','</span>) |
| .filter_map(|s| s.trim().parse::<i32>().ok()) |
| .sum(); |
| <span class="macro">assert_eq!</span>(<span class="number">10</span>, total);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_split_terminator" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#178-180">source</a><h4 class="code-header">fn <a href="#method.par_split_terminator" class="fnname">par_split_terminator</a><P: Pattern>(<br> &self,<br> terminator: P<br>) -> <a class="struct" href="struct.SplitTerminator.html" title="struct rayon::str::SplitTerminator">SplitTerminator</a><'_, P></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over substrings terminated by a |
| given character or predicate, similar to <code>str::split_terminator</code>. |
| It’s equivalent to <code>par_split</code>, except it doesn’t produce an empty |
| substring after a trailing terminator.</p> |
| <p>Note: the <code>Pattern</code> trait is private, for use only by Rayon itself. |
| It is implemented for <code>char</code>, <code>&[char]</code>, and any function or closure |
| <code>F: Fn(char) -> bool + Sync + Send</code>.</p> |
| <h5 id="examples-5"><a href="#examples-5">Examples</a></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>parts: Vec<<span class="kw">_</span>> = <span class="string">"((1 + 3) * 2)" |
| </span>.par_split_terminator(|c| c == <span class="string">'(' </span>|| c == <span class="string">')'</span>) |
| .collect(); |
| <span class="macro">assert_eq!</span>(<span class="macro">vec!</span>[<span class="string">""</span>, <span class="string">""</span>, <span class="string">"1 + 3"</span>, <span class="string">" * 2"</span>], parts);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_lines" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#197-199">source</a><h4 class="code-header">fn <a href="#method.par_lines" class="fnname">par_lines</a>(&self) -> <a class="struct" href="struct.Lines.html" title="struct rayon::str::Lines">Lines</a><'_></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over the lines of a string, ending with an |
| optional carriage return and with a newline (<code>\r\n</code> or just <code>\n</code>). |
| The final line ending is optional, and line endings are not included in |
| the output strings.</p> |
| <h5 id="examples-6"><a href="#examples-6">Examples</a></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>lengths: Vec<<span class="kw">_</span>> = <span class="string">"hello world\nfizbuzz" |
| </span>.par_lines() |
| .map(|l| l.len()) |
| .collect(); |
| <span class="macro">assert_eq!</span>(<span class="macro">vec!</span>[<span class="number">11</span>, <span class="number">7</span>], lengths);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_split_whitespace" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#216-218">source</a><h4 class="code-header">fn <a href="#method.par_split_whitespace" class="fnname">par_split_whitespace</a>(&self) -> <a class="struct" href="struct.SplitWhitespace.html" title="struct rayon::str::SplitWhitespace">SplitWhitespace</a><'_></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over the sub-slices of a string that are |
| separated by any amount of whitespace.</p> |
| <p>As with <code>str::split_whitespace</code>, ‘whitespace’ is defined according to |
| the terms of the Unicode Derived Core Property <code>White_Space</code>.</p> |
| <h5 id="examples-7"><a href="#examples-7">Examples</a></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>longest = <span class="string">"which is the longest word?" |
| </span>.par_split_whitespace() |
| .max_by_key(|word| word.len()); |
| <span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="string">"longest"</span>), longest);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_matches" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#237-242">source</a><h4 class="code-header">fn <a href="#method.par_matches" class="fnname">par_matches</a><P: Pattern>(&self, pattern: P) -> <a class="struct" href="struct.Matches.html" title="struct rayon::str::Matches">Matches</a><'_, P></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over substrings that match a |
| given character or predicate, similar to <code>str::matches</code>.</p> |
| <p>Note: the <code>Pattern</code> trait is private, for use only by Rayon itself. |
| It is implemented for <code>char</code>, <code>&[char]</code>, and any function or closure |
| <code>F: Fn(char) -> bool + Sync + Send</code>.</p> |
| <h5 id="examples-8"><a href="#examples-8">Examples</a></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>total = <span class="string">"1, 2, buckle, 3, 4, door" |
| </span>.par_matches(char::is_numeric) |
| .map(|s| s.parse::<i32>().expect(<span class="string">"digit"</span>)) |
| .sum(); |
| <span class="macro">assert_eq!</span>(<span class="number">10</span>, total);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.par_match_indices" class="method has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#260-265">source</a><h4 class="code-header">fn <a href="#method.par_match_indices" class="fnname">par_match_indices</a><P: Pattern>(&self, pattern: P) -> <a class="struct" href="struct.MatchIndices.html" title="struct rayon::str::MatchIndices">MatchIndices</a><'_, P></h4></section></summary><div class="docblock"><p>Returns a parallel iterator over substrings that match a given character |
| or predicate, with their positions, similar to <code>str::match_indices</code>.</p> |
| <p>Note: the <code>Pattern</code> trait is private, for use only by Rayon itself. |
| It is implemented for <code>char</code>, <code>&[char]</code>, and any function or closure |
| <code>F: Fn(char) -> bool + Sync + Send</code>.</p> |
| <h5 id="examples-9"><a href="#examples-9">Examples</a></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>digits: Vec<<span class="kw">_</span>> = <span class="string">"1, 2, buckle, 3, 4, door" |
| </span>.par_match_indices(char::is_numeric) |
| .collect(); |
| <span class="macro">assert_eq!</span>(digits, <span class="macro">vec!</span>[(<span class="number">0</span>, <span class="string">"1"</span>), (<span class="number">3</span>, <span class="string">"2"</span>), (<span class="number">14</span>, <span class="string">"3"</span>), (<span class="number">17</span>, <span class="string">"4"</span>)]);</code></pre></div> |
| </div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ParallelString-for-str" class="impl has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#268-273">source</a><a href="#impl-ParallelString-for-str" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="trait.ParallelString.html" title="trait rayon::str::ParallelString">ParallelString</a> for str</h3></section></summary><div class="impl-items"><section id="method.as_parallel_string" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/rayon/str.rs.html#270-272">source</a><a href="#method.as_parallel_string" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.as_parallel_string" class="fnname">as_parallel_string</a>(&self) -> &str</h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"></div><script src="../../implementors/rayon/str/trait.ParallelString.js" data-ignore-extern-crates="core" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="rayon" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |