[][src]Struct aho_corasick::packed::Searcher

pub struct Searcher { /* fields omitted */ }

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 aho_corasick::packed::{MatchKind, Searcher};

let searcher = Searcher::new(["foobar", "foo"].iter().cloned())?;
let matches: Vec<usize> = searcher
    .find_iter("foobar")
    .map(|mat| mat.pattern())
    .collect();
assert_eq!(vec![0], matches);

Implementations

impl Searcher[src]

pub fn new<I, P>(patterns: I) -> Option<Searcher> where
    I: IntoIterator<Item = P>,
    P: AsRef<[u8]>, 
[src]

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 None is returned.

Example

Basic usage:

use aho_corasick::packed::{MatchKind, Searcher};

let searcher = Searcher::new(["foobar", "foo"].iter().cloned())?;
let matches: Vec<usize> = searcher
    .find_iter("foobar")
    .map(|mat| mat.pattern())
    .collect();
assert_eq!(vec![0], matches);

pub fn find<B: AsRef<[u8]>>(&self, haystack: B) -> Option<Match>[src]

Return the first occurrence of any of the patterns in this searcher, according to its match semantics, in the given haystack. The Match returned will include the identifier of the pattern that matched, which corresponds to the index of the pattern (starting from 0) in which it was added.

Example

Basic usage:

use aho_corasick::packed::{MatchKind, Searcher};

let searcher = Searcher::new(["foobar", "foo"].iter().cloned())?;
let mat = searcher.find("foobar")?;
assert_eq!(0, mat.pattern());
assert_eq!(0, mat.start());
assert_eq!(6, mat.end());

pub fn find_at<B: AsRef<[u8]>>(&self, haystack: B, at: usize) -> Option<Match>[src]

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 Match returned will include the identifier of the pattern that matched, which corresponds to the index of the pattern (starting from 0) in which it was added. The offsets in the Match will be relative to the start of haystack (and not at).

Example

Basic usage:

use aho_corasick::packed::{MatchKind, Searcher};

let searcher = Searcher::new(["foobar", "foo"].iter().cloned())?;
let mat = searcher.find_at("foofoobar", 3)?;
assert_eq!(0, mat.pattern());
assert_eq!(3, mat.start());
assert_eq!(9, mat.end());

pub fn find_iter<'a, 'b, B: ?Sized + AsRef<[u8]>>(
    &'a self,
    haystack: &'b B
) -> FindIter<'a, 'b>

Notable traits for FindIter<'s, 'h>

impl<'s, 'h> Iterator for FindIter<'s, 'h> type Item = Match;
[src]

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 aho_corasick::packed::{MatchKind, Searcher};

let searcher = Searcher::new(["foobar", "foo"].iter().cloned())?;
let matches: Vec<usize> = searcher
    .find_iter("foobar fooba foofoo")
    .map(|mat| mat.pattern())
    .collect();
assert_eq!(vec![0, 1, 1, 1], matches);

pub fn match_kind(&self) -> &MatchKind[src]

Returns the match kind used by this packed searcher.

Examples

Basic usage:

use aho_corasick::packed::{MatchKind, Searcher};

let searcher = Searcher::new(["foobar", "foo"].iter().cloned())?;
// leftmost-first is the default.
assert_eq!(&MatchKind::LeftmostFirst, searcher.match_kind());

pub fn minimum_len(&self) -> usize[src]

Returns 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.

pub fn heap_bytes(&self) -> usize[src]

Returns the approximate total amount of heap used by this searcher, in units of bytes.

Trait Implementations

impl Clone for Searcher[src]

impl Debug for Searcher[src]

Auto Trait Implementations

impl RefUnwindSafe for Searcher

impl Send for Searcher

impl Sync for Searcher

impl Unpin for Searcher

impl UnwindSafe for Searcher

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.