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§
Sourcefn contains_needle<N: AsRef<[u8]>>(&self, needle: N) -> bool
fn contains_needle<N: AsRef<[u8]>>(&self, needle: N) -> bool
Returns true if this Haystack contains needle.
Sourcefn first_indexof_needle<N: AsRef<[u8]>>(&self, needle: N) -> Option<usize>
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.
Provided Methods§
Sourcefn pattern_table(needle: &[u8]) -> Vec<usize>
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.