pub struct Atom {
pub negative: bool,
pub kind: AtomKind,
/* private fields */
}Expand description
A single pattern component that is matched with a single Matcher function.
Fields§
§negative: boolWhether this pattern atom is a negative match. A negative pattern atom will prevent haystacks matching it from being matchend. It does not contribute to scoring/indices
kind: AtomKindThe kind of match that this pattern performs
Implementations§
Source§impl Atom
impl Atom
Sourcepub fn new(
needle: &str,
case: CaseMatching,
normalize: Normalization,
kind: AtomKind,
escape_whitespace: bool,
) -> Atom
pub fn new( needle: &str, case: CaseMatching, normalize: Normalization, kind: AtomKind, escape_whitespace: bool, ) -> Atom
Creates a single Atom from a string by performing unicode
normalization and case folding (if necessary). Optionally \ can
be escaped to .
Sourcepub fn parse(raw: &str, case: CaseMatching, normalize: Normalization) -> Atom
pub fn parse(raw: &str, case: CaseMatching, normalize: Normalization) -> Atom
Parse a pattern atom from a string. Some special trailing and leading
characters can be used to control the atom kind. See AtomKind for
details.
Sourcepub fn score(
&self,
haystack: Utf32Str<'_>,
matcher: &mut Matcher,
) -> Option<u16>
pub fn score( &self, haystack: Utf32Str<'_>, matcher: &mut Matcher, ) -> Option<u16>
Matches this pattern against haystack (using the allocation and configuration
from matcher) and calculates a ranking score. See the Matcher.
Documentation for more details.
Note: The ignore_case setting is overwritten to match the casing of
each pattern atom.
Sourcepub fn indices(
&self,
haystack: Utf32Str<'_>,
matcher: &mut Matcher,
indices: &mut Vec<u32>,
) -> Option<u16>
pub fn indices( &self, haystack: Utf32Str<'_>, matcher: &mut Matcher, indices: &mut Vec<u32>, ) -> Option<u16>
Matches this pattern against haystack (using the allocation and
configuration from matcher), calculates a ranking score and the match
indices. See the Matcher. Documentation for more
details.
Note: The ignore_case setting is overwritten to match the casing of
each pattern atom.
Note: The indices vector is not cleared by this function.
Sourcepub fn needle_text(&self) -> Utf32Str<'_>
pub fn needle_text(&self) -> Utf32Str<'_>
Returns the needle text that is passed to the matcher. All indices
produced by the indices functions produce char indices used to index
this text
Sourcepub fn match_list<T: AsRef<str>>(
&self,
items: impl IntoIterator<Item = T>,
matcher: &mut Matcher,
) -> Vec<(T, u16)>
pub fn match_list<T: AsRef<str>>( &self, items: impl IntoIterator<Item = T>, matcher: &mut Matcher, ) -> Vec<(T, u16)>
Convenience function to easily match (and sort) a (relatively small) list of inputs.
Note This function is not recommended for building a full fuzzy
matching application that can match large numbers of matches (like all
files in a directory) as all matching is done on the current thread,
effectively blocking the UI. For such applications the high level
nucleo crate can be used instead.