pub unsafe trait Searcher<'a> {
// Required methods
fn haystack(&self) -> &'a str;
fn next(&mut self) -> SearchStep;
// Provided methods
fn next_match(&mut self) -> Option<(usize, usize)> { ... }
fn next_reject(&mut self) -> Option<(usize, usize)> { ... }
}
๐ฌThis is a nightly-only experimental API. (
pattern
)Expand description
A searcher for a string pattern.
This trait provides methods for searching for non-overlapping matches of a pattern starting from the front (left) of a string.
It will be implemented by associated Searcher
types of the Pattern
trait.
The trait is marked unsafe because the indices returned by the
next()
methods are required to lie on valid utf8
boundaries in the haystack. This enables consumers of this trait to
slice the haystack without additional runtime checks.
Required Methodsยง
sourcefn haystack(&self) -> &'a str
๐ฌThis is a nightly-only experimental API. (pattern
)
fn haystack(&self) -> &'a str
pattern
)Getter for the underlying string to be searched in
Will always return the same &str
.
sourcefn next(&mut self) -> SearchStep
๐ฌThis is a nightly-only experimental API. (pattern
)
fn next(&mut self) -> SearchStep
pattern
)Performs the next search step starting from the front.
- Returns
Match(a, b)
ifhaystack[a..b]
matches the pattern. - Returns
Reject(a, b)
ifhaystack[a..b]
can not match the pattern, even partially. - Returns