Struct grep_searcher::sinks::Lossy
source · pub struct Lossy<F>(pub F)
where
F: FnMut(u64, &str) -> Result<bool, Error>;
Expand description
A sink that provides line numbers and matches as (lossily converted) strings while ignoring everything else.
This is like UTF8
, except that if a match contains invalid UTF-8,
then it will be lossily converted to valid UTF-8 by substituting
invalid UTF-8 with Unicode replacement characters.
This implementation will return an error on the first match if the searcher was not configured to count lines.
The closure accepts two parameters: a line number and a UTF-8 string
containing the matched data. The closure returns a
Result<bool, std::io::Error>
. If the bool
is false
, then the
search stops immediately. Otherwise, searching continues.
If multi line mode was enabled, the line number refers to the line number of the first line in the match.
Tuple Fields§
§0: F
Trait Implementations§
source§impl<F> Sink for Lossy<F>
impl<F> Sink for Lossy<F>
source§fn matched(
&mut self,
_searcher: &Searcher,
mat: &SinkMatch<'_>,
) -> Result<bool, Error>
fn matched( &mut self, _searcher: &Searcher, mat: &SinkMatch<'_>, ) -> Result<bool, Error>
This method is called whenever a match is found. Read more
source§fn context(
&mut self,
_searcher: &Searcher,
_context: &SinkContext<'_>,
) -> Result<bool, Self::Error>
fn context( &mut self, _searcher: &Searcher, _context: &SinkContext<'_>, ) -> Result<bool, Self::Error>
This method is called whenever a context line is found, and is optional
to implement. By default, it does nothing and returns
true
. Read moresource§fn context_break(&mut self, _searcher: &Searcher) -> Result<bool, Self::Error>
fn context_break(&mut self, _searcher: &Searcher) -> Result<bool, Self::Error>
This method is called whenever a break in contextual lines is found,
and is optional to implement. By default, it does nothing and returns
true
. Read moresource§fn binary_data(
&mut self,
_searcher: &Searcher,
_binary_byte_offset: u64,
) -> Result<bool, Self::Error>
fn binary_data( &mut self, _searcher: &Searcher, _binary_byte_offset: u64, ) -> Result<bool, Self::Error>
This method is called whenever binary detection is enabled and binary
data is found. If binary data is found, then this is called at least
once for the first occurrence with the absolute byte offset at which
the binary data begins. Read more
Auto Trait Implementations§
impl<F> Freeze for Lossy<F>where
F: Freeze,
impl<F> RefUnwindSafe for Lossy<F>where
F: RefUnwindSafe,
impl<F> Send for Lossy<F>where
F: Send,
impl<F> Sync for Lossy<F>where
F: Sync,
impl<F> Unpin for Lossy<F>where
F: Unpin,
impl<F> UnwindSafe for Lossy<F>where
F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)