π¬This is a nightly-only experimental API. (
pattern
#27721)Expand description
The string Pattern API.
The Pattern API provides a generic mechanism for using different pattern types when searching through a string.
For more details, see the traits Pattern
, Searcher
,
ReverseSearcher
, and DoubleEndedSearcher
.
Although this API is unstable, it is exposed via stable APIs on the
str
type.
Β§Examples
Pattern
is implemented in the stable API for
&str
, char
, slices of char
, and functions and closures
implementing FnMut(char) -> bool
.
let s = "Can you find a needle in a haystack?";
// &str pattern
assert_eq!(s.find("you"), Some(4));
// char pattern
assert_eq!(s.find('n'), Some(2));
// array of chars pattern
assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u']), Some(1));
// slice of chars pattern
assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u'][..]), Some(1));
// closure pattern
assert_eq!(s.find(|c: char| c.is_ascii_punctuation()), Some(35));
MacrosΒ§
- pattern_
methods πExperimental - searcher_
methods πExperimental
StructsΒ§
- Char
Array RefSearcher Experimental - Associated type for
<&[char; N] as Pattern>::Searcher<'a>
. - Char
Array Searcher Experimental - Associated type for
<[char; N] as Pattern>::Searcher<'a>
. - Char
Predicate Searcher Experimental - Associated type for
<F as Pattern>::Searcher<'a>
. - Char
Searcher Experimental - Associated type for
<char as Pattern>::Searcher<'a>
. - Char
Slice Searcher Experimental - Associated type for
<&[char] as Pattern>::Searcher<'a>
. - Empty
Needle πExperimental - Multi
Char πEqPattern Experimental - Multi
Char πEqSearcher Experimental - StrSearcher
Experimental - Associated type for
<&str as Pattern>::Searcher<'a>
. - TwoWay
Searcher πExperimental - The internal state of the two-way substring search algorithm.
EnumsΒ§
- Match
Only πExperimental - Skip to match intervals as quickly as possible
- Reject
AndMatch πExperimental - Emit Rejects regularly
- Search
Step Experimental - Result of calling
Searcher::next()
orReverseSearcher::next_back()
. - StrSearcher
Impl πExperimental - Utf8
Pattern Experimental - Result of calling
Pattern::as_utf8_pattern()
. Can be used for inspecting the contents of aPattern
in cases where the underlying representation can be represented as UTF-8.
TraitsΒ§
- Double
Ended Searcher Experimental - A marker trait to express that a
ReverseSearcher
can be used for aDoubleEndedIterator
implementation. - Multi
Char ππ»Eq Experimental - Pattern
Experimental - A string pattern.
- Reverse
Searcher Experimental - A reverse searcher for a string pattern.
- Searcher
Experimental - A searcher for a string pattern.
- TwoWay
Strategy πExperimental
FunctionsΒ§
- simd_
contains πExperimental - SIMD search for short needles based on Wojciech MuΕaβs βSIMD-friendly algorithms for substring searchingβ0
- small_
slice_ π βeq Experimental - Compares short slices for equality.