kvarn_utils::prelude::str::pattern

Trait Searcher

source
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ยง

source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (pattern)

Getter for the underlying string to be searched in

Will always return the same &str.

source

fn next(&mut self) -> SearchStep

๐Ÿ”ฌThis is a nightly-only experimental API. (pattern)

Performs the next search step starting from the front.

  • Returns Match(a, b) if haystack[a..b] matches the pattern.
  • Returns Reject(a, b) if haystack[a..b] can not match the pattern, even partially.
  • Returns