[][src]Trait kmpsearch::Haystack

pub trait Haystack {
    fn contains_needle<N: AsRef<[u8]>>(&self, needle: N) -> bool;
fn first_indexof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<usize>;
fn last_indexof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<usize>;
fn indexesof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<Vec<usize>>; fn pattern_table(needle: &[u8]) -> Vec<usize> { ... } }

The Haystack trait is the 'target' of the KMP algorithm provided by this library. It provides the pattern_table method (part of the KMP algorithm) and the various methods for searching. Haystack is implemented on all types that can be converted to a &u8, such as Byte slices, str and Strings.

Required methods

fn contains_needle<N: AsRef<[u8]>>(&self, needle: N) -> bool

Returns true if this Haystack contains needle.

fn first_indexof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<usize>

Returns the first index of needle in this Haystack, or None if it doesn't contain the needle.

fn last_indexof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<usize>

Returns the last index of needle in this Haystack, or None if it doesn't contain the needle.

fn indexesof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<Vec<usize>>

Returns the last index of needle in this Haystack, or None if it doesn't contain the needle.

Loading content...

Provided methods

fn pattern_table(needle: &[u8]) -> Vec<usize>

Produce a 'pattern table' for use with the Knuth Morris Pratt algorithm.

Loading content...

Implementors

impl<H: AsRef<[u8]>> Haystack for H[src]

Implementation allowing anything convertible to a &u8 to use Haystack methods.

fn pattern_table(needle: &[u8]) -> Vec<usize>[src]

Loading content...