Struct grep_printer::JSONSink

source ·
pub struct JSONSink<'p, 's, M: Matcher, W> { /* private fields */ }
Available on crate feature serde only.
Expand description

An implementation of Sink associated with a matcher and an optional file path for the JSON printer.

This type is generic over a few type parameters:

  • 'p refers to the lifetime of the file path, if one is provided. When no file path is given, then this is 'static.
  • 's refers to the lifetime of the JSON printer that this type borrows.
  • M refers to the type of matcher used by grep_searcher::Searcher that is reporting results to this sink.
  • W refers to the underlying writer that this printer is writing its output to.

Implementations§

source§

impl<'p, 's, M: Matcher, W: Write> JSONSink<'p, 's, M, W>

source

pub fn has_match(&self) -> bool

Returns true if and only if this printer received a match in the previous search.

This is unaffected by the result of searches before the previous search.

source

pub fn match_count(&self) -> u64

Return the total number of matches reported to this sink.

This corresponds to the number of times Sink::matched is called.

source

pub fn binary_byte_offset(&self) -> Option<u64>

If binary data was found in the previous search, this returns the offset at which the binary data was first detected.

The offset returned is an absolute offset relative to the entire set of bytes searched.

This is unaffected by the result of searches before the previous search. e.g., If the search prior to the previous search found binary data but the previous search found no binary data, then this will return None.

source

pub fn stats(&self) -> &Stats

Return a reference to the stats produced by the printer for all searches executed on this sink.

Trait Implementations§

source§

impl<'p, 's, M: Debug + Matcher, W: Debug> Debug for JSONSink<'p, 's, M, W>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'p, 's, M: Matcher, W: Write> Sink for JSONSink<'p, 's, M, W>

source§

type Error = Error

The type of an error that should be reported by a searcher. Read more
source§

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, ctx: &SinkContext<'_>, ) -> Result<bool, 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 more
source§

fn binary_data( &mut self, searcher: &Searcher, binary_byte_offset: u64, ) -> Result<bool, 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
source§

fn begin(&mut self, _searcher: &Searcher) -> Result<bool, Error>

This method is called when a search has begun, before any search is executed. By default, this does nothing. Read more
source§

fn finish( &mut self, _searcher: &Searcher, finish: &SinkFinish, ) -> Result<(), Error>

This method is called when a search has completed. By default, this does nothing. Read more
source§

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 more

Auto Trait Implementations§

§

impl<'p, 's, M, W> Freeze for JSONSink<'p, 's, M, W>
where M: Freeze,

§

impl<'p, 's, M, W> RefUnwindSafe for JSONSink<'p, 's, M, W>

§

impl<'p, 's, M, W> Send for JSONSink<'p, 's, M, W>
where M: Send, W: Send,

§

impl<'p, 's, M, W> Sync for JSONSink<'p, 's, M, W>
where M: Sync, W: Sync,

§

impl<'p, 's, M, W> Unpin for JSONSink<'p, 's, M, W>
where M: Unpin,

§

impl<'p, 's, M, W> !UnwindSafe for JSONSink<'p, 's, M, W>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

source§

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 T
where U: TryFrom<T>,

source§

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.