Struct Searcher
struct Searcher { ... }
A packed searcher for quickly finding occurrences of multiple patterns.
If callers need more flexible construction, or if one wants to change the
match semantics (either leftmost-first or leftmost-longest), then one can
use the Config and/or Builder types for more fine grained control.
Example
This example shows how to create a searcher from an iterator of patterns. By default, leftmost-first match semantics are used.
use ;
#
# if cfg! else
Implementations
impl Searcher
fn new<I, P>(patterns: I) -> Option<Searcher> where I: IntoIterator<Item = P>, P: AsRef<[u8]>A convenience function for constructing a searcher from an iterator of things that can be converted to a
&[u8].If a searcher could not be constructed (either because of an unsupported CPU or because there are too many patterns), then
Noneis returned.Example
Basic usage:
use ; # # if cfg! elsefn config() -> ConfigA convenience function for calling
Config::new().This is useful for avoiding an additional import.
fn builder() -> BuilderA convenience function for calling
Builder::new().This is useful for avoiding an additional import.
fn find<B: AsRef<[u8]>>(self: &Self, haystack: B) -> Option<Match>Return the first occurrence of any of the patterns in this searcher, according to its match semantics, in the given haystack. The
Matchreturned will include the identifier of the pattern that matched, which corresponds to the index of the pattern (starting from0) in which it was added.Example
Basic usage:
use ; # # if cfg! elsefn find_in<B: AsRef<[u8]>>(self: &Self, haystack: B, span: Span) -> Option<Match>Return the first occurrence of any of the patterns in this searcher, according to its match semantics, in the given haystack starting from the given position.
The
Matchreturned will include the identifier of the pattern that matched, which corresponds to the index of the pattern (starting from0) in which it was added. The offsets in theMatchwill be relative to the start ofhaystack(and notat).Example
Basic usage:
use ; # # if cfg! elsefn find_iter<'a, 'b, B: ?Sized + AsRef<[u8]>>(self: &'a Self, haystack: &'b B) -> FindIter<'a, 'b>Return an iterator of non-overlapping occurrences of the patterns in this searcher, according to its match semantics, in the given haystack.
Example
Basic usage:
use ; # # if cfg! elsefn match_kind(self: &Self) -> &MatchKindReturns the match kind used by this packed searcher.
Examples
Basic usage:
use ; # # if cfg! elsefn minimum_len(self: &Self) -> usizeReturns the minimum length of a haystack that is required in order for packed searching to be effective.
In some cases, the underlying packed searcher may not be able to search very short haystacks. When that occurs, the implementation will defer to a slower non-packed searcher (which is still generally faster than Aho-Corasick for a small number of patterns). However, callers may want to avoid ever using the slower variant, which one can do by never passing a haystack shorter than the minimum length returned by this method.
fn memory_usage(self: &Self) -> usizeReturns the approximate total amount of heap used by this searcher, in units of bytes.
impl Clone for Searcher
fn clone(self: &Self) -> Searcher
impl Debug for Searcher
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for Searcher
impl RefUnwindSafe for Searcher
impl Send for Searcher
impl Sync for Searcher
impl Unpin for Searcher
impl UnsafeUnpin for Searcher
impl UnwindSafe for Searcher
impl<T> Any for Searcher
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Searcher
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Searcher
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Searcher
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Searcher
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Searcher
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Searcher
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Searcher
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Searcher
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>