Trait core::str::pattern::Searcher [] [src]

pub unsafe trait Searcher<'a> {
    fn haystack(&self) -> &'a str;
    fn next(&mut self) -> SearchStep;

    fn next_match(&mut self) -> Option<(usize, usize)> { ... }
    fn next_reject(&mut self) -> Option<(usize, usize)> { ... }
}
Unstable

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`Searchertypes of the` types of the Pattern`Pattern` trait.

The trait is marked unsafe because the indices returned by the next()`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

fn haystack(&self) -> &'a str

Unstable

Getter for the underlaying string to be searched in

Will always return the same &str`&str`

fn next(&mut self) -> SearchStep

Unstable

Performs the next search step starting from the front.

  • Returns Match(a, b)`Match(a, b)if` if haystack[a..b]`haystack[a..b]` matches the pattern.
  • Returns Reject(a, b)`Reject(a, b)if` if haystack[a..b]`haystack[a..b]` can not match the pattern, even partially.
  • Returns Done`Done` if every byte of the haystack has been visited

The stream of Match`Matchand` and Reject`Rejectvalues up to a` values up to a Done`Done` will contain index ranges that are adjacent, non-overlapping, covering the whole haystack, and laying on utf8 boundaries.

A Match`Matchresult needs to contain the whole matched pattern, however` result needs to contain the whole matched pattern, however Reject`Reject` results may be split up into arbitrary many adjacent fragments. Both ranges may have zero length.

As an example, the pattern "aaa"`"aaa"and the haystack` and the haystack "cbaaaaab"`"cbaaaaab"might produce the stream` might produce the stream [Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]`[Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]`

Provided Methods

fn next_match(&mut self) -> Option<(usize, usize)>

Unstable

Find the next Match`Matchresult. See` result. See next()`next()`

fn next_reject(&mut self) -> Option<(usize, usize)>

Unstable

Find the next Reject`Rejectresult. See` result. See next()`next()`

Implementors