Trait Haystack

Source
pub trait Haystack {
    // Required methods
    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>>;

    // Provided method
    fn pattern_table(needle: &[u8]) -> Vec<usize> { ... }
}
Expand description

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§

Source

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

Returns true if this Haystack contains needle.

Source

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.

Source

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.

Source

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.

Provided Methods§

Source

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

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

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