doc.rust-lang.org
pub struct Matches<'a, P>
Matches — Created with the method matches.
struct
core
Stable since 1.2.0
Version 1.100.0-nightly
doc.rust-lang.org
pub macro matches!
matches — Returns whether the given expression matches the provided pattern.
The pattern syntax is exactly the same as found in a match arm. The optional if guard can be used to add additional checks that must be true for the matched value, otherwise this macro will return false.
When testing...
macro
core
Stable since 1.42.0
Version 1.100.0-nightly
doc.rust-lang.org
pub macro debug_assert_matches!
debug_assert_matches — Asserts that an expression matches the provided pattern.
This macro is generally preferable to debug_assert!(matches!(value, pattern)), because it can print the debug representation of the actual value shape that did not meet expectations. In contrast, using debug_assert! will only print that expectations were...
macro
core
Stable since 1.96.0
Version 1.100.0-nightly
doc.rust-lang.org
pub macro assert_matches!
assert_matches — Asserts that an expression matches the provided pattern.
This macro is generally preferable to assert!(matches!(value, pattern)), because it can print the debug representation of the actual value shape that did not meet expectations. In contrast, using assert! will only print that expectations were not met, but...
macro
core
Stable since 1.96.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn match_indices<P>(&self, pat: P) -> MatchIndices<'_, P>
str::match_indices — Returns an iterator over the disjoint matches of a pattern within this string slice as well as the index that the match starts at.
For matches of pat within self that overlap, only the indices corresponding to the first match are returned.
The pattern can be a...
method
core
Stable since 1.5.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn trim_matches<P>(&self, pat: P) -> &str
str::trim_matches — Returns a string slice with all prefixes and suffixes that match a pattern repeatedly removed.
The pattern can be a char, a slice of chars, or a function or closure that determines if a character matches.
Examples
Simple patterns:
assert_eq!("11foo1bar11".trim_matches('1'), "foo1bar");
assert...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn trim_right_matches<P>(&self, pat: P) -> &str
str::trim_right_matches — Returns a string slice with all suffixes that match a pattern repeatedly removed.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Text directionality
A string is a sequence of bytes. 'Right' in...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn trim_end_matches<P>(&self, pat: P) -> &str
str::trim_end_matches — Returns a string slice with all suffixes that match a pattern repeatedly removed.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Text directionality
A string is a sequence of bytes. end in...
method
core
Stable since 1.30.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn trim_left_matches<P>(&self, pat: P) -> &str
str::trim_left_matches — Returns a string slice with all prefixes that match a pattern repeatedly removed.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Text directionality
A string is a sequence of bytes. 'Left' in...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn trim_start_matches<P>(&self, pat: P) -> &str
str::trim_start_matches — Returns a string slice with all prefixes that match a pattern repeatedly removed.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Text directionality
A string is a sequence of bytes. start in...
method
core
Stable since 1.30.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn matches<P>(&self, pat: P) -> Matches<'_, P>
str::matches — Returns an iterator over the disjoint matches of a pattern within the given string slice.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
Iterator behavior
The returned iterator will be a DoubleEndedIterator if the...
method
core
Stable since 1.2.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn rmatch_indices<P>(&self, pat: P) -> RMatchIndices<'_, P>
str::rmatch_indices — Returns an iterator over the disjoint matches of a pattern within self, yielded in reverse order along with the index of the match.
For matches of pat within self that overlap, only the indices corresponding to the last match are returned.
The pattern can be a &str...
method
core
Stable since 1.5.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn split<F>(&self, pred: F) -> Split<'_, T, F>
slice::split — Returns an iterator over subslices separated by elements that match pred. The matched element is not contained in the subslices.
Examples
let slice = [10, 40, 33, 20];
let mut iter = slice.split(|num| num % 3 == 0);
assert_eq!(iter.next().unwrap(), &[10, 40]);
assert_eq!(iter.next().unwrap...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn split_inclusive<F>(&self, pred: F) -> SplitInclusive<'_, T, F>
slice::split_inclusive — Returns an iterator over subslices separated by elements that match pred. The matched element is contained in the end of the previous subslice as a terminator.
Examples
let slice = [10, 40, 33, 20];
let mut iter = slice.split_inclusive(|num| num % 3 == 0);
assert_eq!(iter.next...
method
core
Stable since 1.51.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
...If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could...
method
alloc
Stable since 1.54.0
Version 1.100.0-nightly
doc.rust-lang.org
pub enum ErrorKind
...This list is intended to grow over time and it is not recommended to exhaustively match against it.
It is used with the io::Error type.
Handling errors and matching on ErrorKind
In application code, use match for the ErrorKind values you are expecting; use _ to match "all other errors...
enum
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn binary_search(&self, x: &T) -> Result<usize, usize>
...If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. The index is chosen deterministically, but is subject to change in future versions of Rust. If the value is...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn rsplit<F>(&self, pred: F) -> RSplit<'_, T, F>
slice::rsplit — Returns an iterator over subslices separated by elements that match pred, starting at the end of the slice and working backwards. The matched element is not contained in the subslices.
Examples
let slice = [11, 22, 33, 0, 44, 55];
let mut iter = slice.rsplit(|num| *num == 0);
assert...
method
core
Stable since 1.27.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn split_inclusive<P>(&self, pat: P) -> SplitInclusive<'_, P>
str::split_inclusive — Returns an iterator over substrings of this string slice, separated by characters matched by a pattern.
Differs from the iterator produced by split in that split_inclusive leaves the matched part as the terminator of the substring.
The pattern can be a &str, char, a slice of...
method
core
Stable since 1.51.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
...If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Result::Err is returned, containing the index where a matching element could...
method
alloc
Stable since 1.54.0
Version 1.100.0-nightly