Trait pattern_3::needle::Needle

source ·
pub trait Needle<H: Haystack>: Sizedwhere
    H::Target: Hay,
{ type Searcher: Searcher<H::Target>; type Consumer: Consumer<H::Target>; fn into_searcher(self) -> Self::Searcher; fn into_consumer(self) -> Self::Consumer; }
Expand description

A needle, a type which can be converted into a searcher.

When using search algorithms like split(), users will search with a Needle e.g. a &str. A needle is usually stateless, however for efficient searching, we often need some preprocessing and maintain a mutable state. The preprocessed structure is called the Searcher of this needle.

The relationship between Searcher and Needle is similar to Iterator and IntoIterator.

Required Associated Types§

The searcher associated with this needle.

The consumer associated with this needle.

Required Methods§

Produces a searcher for this needle.

Produces a consumer for this needle.

Usually a consumer and a searcher can be the same type. Some needles may require different types when the two need different optimization strategies. String searching is an example of this: we use the Two-Way Algorithm when searching for substrings, which needs to preprocess the needle. However this is irrelevant for consuming, which only needs to check for string equality once. Therefore the Consumer for a string would be a distinct type using naive search.

Implementations on Foreign Types§

Implementors§