Struct grep_searcher::Searcher

source ·
pub struct Searcher { /* private fields */ }
Expand description

A searcher executes searches over a haystack and writes results to a caller provided sink.

Matches are detected via implementations of the Matcher trait, which must be provided by the caller when executing a search.

When possible, a searcher should be reused.

Implementations§

source§

impl Searcher

source

pub fn new() -> Searcher

Create a new searcher with a default configuration.

To configure the searcher (e.g., invert matching, enable memory maps, enable contexts, etc.), use the SearcherBuilder.

source

pub fn search_path<P, M, S>( &mut self, matcher: M, path: P, write_to: S ) -> Result<(), S::Error>where P: AsRef<Path>, M: Matcher, S: Sink,

Execute a search over the file with the given path and write the results to the given sink.

If memory maps are enabled and the searcher heuristically believes memory maps will help the search run faster, then this will use memory maps. For this reason, callers should prefer using this method or search_file over the more generic search_reader when possible.

source

pub fn search_file<M, S>( &mut self, matcher: M, file: &File, write_to: S ) -> Result<(), S::Error>where M: Matcher, S: Sink,

Execute a search over a file and write the results to the given sink.

If memory maps are enabled and the searcher heuristically believes memory maps will help the search run faster, then this will use memory maps. For this reason, callers should prefer using this method or search_path over the more generic search_reader when possible.

source

pub fn search_reader<M, R, S>( &mut self, matcher: M, read_from: R, write_to: S ) -> Result<(), S::Error>where M: Matcher, R: Read, S: Sink,

Execute a search over any implementation of std::io::Read and write the results to the given sink.

When possible, this implementation will search the reader incrementally without reading it into memory. In some cases—for example, if multi line search is enabled—an incremental search isn’t possible and the given reader is consumed completely and placed on the heap before searching begins. For this reason, when multi line search is enabled, one should try to use higher level APIs (e.g., searching by file or file path) so that memory maps can be used if they are available and enabled.

source

pub fn search_slice<M, S>( &mut self, matcher: M, slice: &[u8], write_to: S ) -> Result<(), S::Error>where M: Matcher, S: Sink,

Execute a search over the given slice and write the results to the given sink.

source

pub fn set_binary_detection(&mut self, detection: BinaryDetection)

Set the binary detection method used on this searcher.

source§

impl Searcher

The following methods permit querying the configuration of a searcher. These can be useful in generic implementations of Sink, where the output may be tailored based on how the searcher is configured.

source

pub fn line_terminator(&self) -> LineTerminator

Returns the line terminator used by this searcher.

source

pub fn binary_detection(&self) -> &BinaryDetection

Returns the type of binary detection configured on this searcher.

source

pub fn invert_match(&self) -> bool

Returns true if and only if this searcher is configured to invert its search results. That is, matching lines are lines that do not match the searcher’s matcher.

source

pub fn line_number(&self) -> bool

Returns true if and only if this searcher is configured to count line numbers.

source

pub fn multi_line(&self) -> bool

Returns true if and only if this searcher is configured to perform multi line search.

source

pub fn stop_on_nonmatch(&self) -> bool

Returns true if and only if this searcher is configured to stop when in finds a non-matching line after a matching one.

source

pub fn multi_line_with_matcher<M: Matcher>(&self, matcher: M) -> bool

Returns true if and only if this searcher will choose a multi-line strategy given the provided matcher.

This may diverge from the result of multi_line in cases where the searcher has been configured to execute a search that can report matches over multiple lines, but where the matcher guarantees that it will never produce a match over multiple lines.

source

pub fn after_context(&self) -> usize

Returns the number of “after” context lines to report. When context reporting is not enabled, this returns 0.

source

pub fn before_context(&self) -> usize

Returns the number of “before” context lines to report. When context reporting is not enabled, this returns 0.

source

pub fn passthru(&self) -> bool

Returns true if and only if the searcher has “passthru” mode enabled.

Trait Implementations§

source§

impl Clone for Searcher

source§

fn clone(&self) -> Searcher

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Searcher

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.