Trait ParallelString
trait ParallelString
Parallel extensions for strings.
Required Methods
fn as_parallel_string(self: &Self) -> &strReturns a plain string slice, which is used to implement the rest of the parallel methods.
Provided Methods
fn par_chars(self: &Self) -> Chars<'_>Returns a parallel iterator over the characters of a string.
Examples
use *; let max = "hello".par_chars.max_by_key; assert_eq!;fn par_char_indices(self: &Self) -> CharIndices<'_>Returns a parallel iterator over the characters of a string, with their positions.
Examples
use *; let min = "hello".par_char_indices.min_by_key; assert_eq!;fn par_bytes(self: &Self) -> Bytes<'_>Returns a parallel iterator over the bytes of a string.
Note that multi-byte sequences (for code points greater than
U+007F) are produced as separate items, but will not be split across threads. If you would prefer an indexed iterator without that guarantee, considerstring.as_bytes().par_iter().copied()instead.Examples
use *; let max = "hello".par_bytes.max; assert_eq!;fn par_encode_utf16(self: &Self) -> EncodeUtf16<'_>Returns a parallel iterator over a string encoded as UTF-16.
Note that surrogate pairs (for code points greater than
U+FFFF) are produced as separate items, but will not be split across threads.Examples
use *; let max = "hello".par_encode_utf16.max; assert_eq!; let text = "Zażółć gęślą jaźń"; let utf8_len = text.len; let utf16_len = text.par_encode_utf16.count; assert!;fn par_split<P: Pattern>(self: &Self, separator: P) -> Split<'_, P>Returns a parallel iterator over substrings separated by a given character or predicate, similar to
str::split.Note: the
Patterntrait is private, for use only by Rayon itself. It is implemented forchar,&[char],[char; N],&[char; N], and any function or closureF: Fn(char) -> bool + Sync + Send.Examples
use *; let total = "1, 2, buckle, 3, 4, door" .par_split .filter_map .sum; assert_eq!;fn par_split_inclusive<P: Pattern>(self: &Self, separator: P) -> SplitInclusive<'_, P>Returns a parallel iterator over substrings separated by a given character or predicate, keeping the matched part as a terminator of the substring similar to
str::split_inclusive.Note: the
Patterntrait is private, for use only by Rayon itself. It is implemented forchar,&[char],[char; N],&[char; N], and any function or closureF: Fn(char) -> bool + Sync + Send.Examples
use *; let lines: = "Mary had a little lamb\nlittle lamb\nlittle lamb." .par_split_inclusive .collect; assert_eq!;fn par_split_terminator<P: Pattern>(self: &Self, terminator: P) -> SplitTerminator<'_, P>Returns a parallel iterator over substrings terminated by a given character or predicate, similar to
str::split_terminator. It's equivalent topar_split, except it doesn't produce an empty substring after a trailing terminator.Note: the
Patterntrait is private, for use only by Rayon itself. It is implemented forchar,&[char],[char; N],&[char; N], and any function or closureF: Fn(char) -> bool + Sync + Send.Examples
use *; let parts: = "((1 + 3) * 2)" .par_split_terminator .collect; assert_eq!;fn par_lines(self: &Self) -> Lines<'_>Returns a parallel iterator over the lines of a string, ending with an optional carriage return and with a newline (
\r\nor just\n). The final line ending is optional, and line endings are not included in the output strings.Examples
use *; let lengths: = "hello world\nfizbuzz" .par_lines .map .collect; assert_eq!;fn par_split_whitespace(self: &Self) -> SplitWhitespace<'_>Returns a parallel iterator over the sub-slices of a string that are separated by any amount of whitespace.
As with
str::split_whitespace, 'whitespace' is defined according to the terms of the Unicode Derived Core PropertyWhite_Space. If you only want to split on ASCII whitespace instead, use [par_split_ascii_whitespace]ParallelString::par_split_ascii_whitespace.Examples
use *; let longest = "which is the longest word?" .par_split_whitespace .max_by_key; assert_eq!;All kinds of whitespace are considered:
use *; let words: = " Mary had\ta\u{2009}little \n\t lamb" .par_split_whitespace .collect; assert_eq!;If the string is empty or all whitespace, the iterator yields no string slices:
use *; assert_eq!; assert_eq!;fn par_split_ascii_whitespace(self: &Self) -> SplitAsciiWhitespace<'_>Returns a parallel iterator over the sub-slices of a string that are separated by any amount of ASCII whitespace.
To split by Unicode
White_Spaceinstead, use [par_split_whitespace]ParallelString::par_split_whitespace.Examples
use *; let longest = "which is the longest word?" .par_split_ascii_whitespace .max_by_key; assert_eq!;All kinds of ASCII whitespace are considered, but not Unicode
White_Space:use *; let words: = " Mary had\ta\u{2009}little \n\t lamb" .par_split_ascii_whitespace .collect; assert_eq!;If the string is empty or all ASCII whitespace, the iterator yields no string slices:
use *; assert_eq!; assert_eq!;fn par_matches<P: Pattern>(self: &Self, pattern: P) -> Matches<'_, P>Returns a parallel iterator over substrings that match a given character or predicate, similar to
str::matches.Note: the
Patterntrait is private, for use only by Rayon itself. It is implemented forchar,&[char],[char; N],&[char; N], and any function or closureF: Fn(char) -> bool + Sync + Send.Examples
use *; let total = "1, 2, buckle, 3, 4, door" .par_matches .map .sum; assert_eq!;fn par_match_indices<P: Pattern>(self: &Self, pattern: P) -> MatchIndices<'_, P>Returns a parallel iterator over substrings that match a given character or predicate, with their positions, similar to
str::match_indices.Note: the
Patterntrait is private, for use only by Rayon itself. It is implemented forchar,&[char],[char; N],&[char; N], and any function or closureF: Fn(char) -> bool + Sync + Send.Examples
use *; let digits: = "1, 2, buckle, 3, 4, door" .par_match_indices .collect; assert_eq!;
Implementors
impl ParallelString for str