Needle

Trait Needle 

Source
pub trait Needle<H: Haystack>: Sized
where H::Target: Hay,
{ type Searcher: Searcher<H::Target>; type Consumer: Consumer<H::Target>; // Required methods 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§

Source

type Searcher: Searcher<H::Target>

The searcher associated with this needle.

Source

type Consumer: Consumer<H::Target>

The consumer associated with this needle.

Required Methods§

Source

fn into_searcher(self) -> Self::Searcher

Produces a searcher for this needle.

Source

fn into_consumer(self) -> Self::Consumer

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.

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.

Implementations on Foreign Types§

Source§

impl<'h, 'p> Needle<&'h str> for &'p [char]

Source§

type Searcher = MultiCharSearcher<MultiCharEq<'p>>

Source§

type Consumer = MultiCharSearcher<MultiCharEq<'p>>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'h, 'p> Needle<&'h Wtf8> for &'p str

Source§

type Searcher = SliceSearcher<'p, u8>

Source§

type Consumer = NaiveSearcher<'p, u8>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'h, 'p> Needle<&'h mut str> for &'p [char]

Source§

type Searcher = MultiCharSearcher<MultiCharEq<'p>>

Source§

type Consumer = MultiCharSearcher<MultiCharEq<'p>>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'p, 'h, T> Needle<&'h [T]> for &'p [T]
where T: PartialEq + 'p,

Source§

type Searcher = SliceSearcher<'p, T>

Source§

type Consumer = NaiveSearcher<'p, T>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'p, 'h, T> Needle<&'h mut [T]> for &'p [T]
where T: PartialEq + 'p,

Source§

type Searcher = SliceSearcher<'p, T>

Source§

type Consumer = NaiveSearcher<'p, T>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'p, H: Haystack<Target = str>> Needle<H> for &'p str

Source§

type Searcher = SliceSearcher<'p, u8>

Source§

type Consumer = NaiveSearcher<'p, u8>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'p, H: Haystack<Target = str>> Needle<H> for &'p String

Source§

type Searcher = SliceSearcher<'p, u8>

Source§

type Consumer = NaiveSearcher<'p, u8>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'p, T> Needle<Vec<T>> for &'p [T]
where T: PartialEq + 'p,

Source§

type Searcher = SliceSearcher<'p, T>

Source§

type Consumer = NaiveSearcher<'p, T>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<'q, 'p, H: Haystack<Target = str>> Needle<H> for &'q &'p str

Source§

type Searcher = SliceSearcher<'p, u8>

Source§

type Consumer = NaiveSearcher<'p, u8>

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Source§

impl<H: Haystack<Target = str>> Needle<H> for char

Source§

type Searcher = CharSearcher

Source§

type Consumer = CharSearcher

Source§

fn into_searcher(self) -> Self::Searcher

Source§

fn into_consumer(self) -> Self::Consumer

Implementors§

Source§

impl<'h, F: FnMut(char) -> bool> Needle<&'h str> for F

Source§

type Searcher = MultiCharSearcher<F>

Source§

type Consumer = MultiCharSearcher<F>

Source§

impl<'h, F: FnMut(char) -> bool> Needle<&'h mut str> for F

Source§

type Searcher = MultiCharSearcher<F>

Source§

type Consumer = MultiCharSearcher<F>

Source§

impl<'h, T, F> Needle<&'h [T]> for F
where F: FnMut(&T) -> bool,

Source§

type Searcher = ElemSearcher<F>

Source§

type Consumer = ElemSearcher<F>

Source§

impl<'h, T, F> Needle<&'h mut [T]> for F
where F: FnMut(&T) -> bool,

Source§

type Searcher = ElemSearcher<F>

Source§

type Consumer = ElemSearcher<F>

Source§

impl<'p, H: Haystack<Target = Wtf8>> Needle<H> for &'p Wtf8

Source§

type Searcher = Wtf8Searcher<SliceSearcher<'p, u8>>

Source§

type Consumer = Wtf8Searcher<NaiveSearcher<'p, u8>>

Source§

impl<T, F> Needle<Vec<T>> for F
where F: FnMut(&T) -> bool,

Source§

type Searcher = ElemSearcher<F>

Source§

type Consumer = ElemSearcher<F>