Skip to main content

Scanner

Struct Scanner 

Source
pub struct Scanner { /* private fields */ }

Implementations§

Source§

impl Scanner

Source

pub fn new(finders: Vec<Box<dyn Finder>>) -> Self

Source

pub fn try_new(finders: Vec<Box<dyn Finder>>) -> Result<Self, ScannerError>

Source

pub fn finders(&self) -> &[Box<dyn Finder>]

Source

pub fn strategy(&self) -> Strategy

The line-walking strategy in use.

Source

pub fn set_strategy(&mut self, strategy: Strategy)

Selects the line-walking strategy; results do not depend on it.

Source

pub fn backend(&self) -> &'static str

Name of the block classifier used by Strategy::Vector ("neon", "ssse3" or "scalar"), for diagnostics.

Source

pub fn plan(&self) -> String

How Strategy::Vector searches candidates, for diagnostics: the passes in order, such as anchors(-), start bytes(:@) or blocks, joined with +.

Source

pub fn scan_line(&self, line: &str) -> Vec<Match>

Source

pub fn skip_to_candidate_line(&self, text: &[u8], from: usize) -> Option<usize>

Start of the first line at or after from (itself a line start) in text that may contain a match, or None when no later line can.

When the finders start at three bytes or fewer, those bytes are searched with memchr across the whole buffer, so lines that cannot match are never visited individually; otherwise every line is a candidate and from is returned. Lines end at \n.

Source

pub fn scan_line_into(&self, line: &str, matches: &mut Vec<Match>)

Source

pub fn scan_line_stats( &self, line: &str, matches: &mut Vec<Match>, stats: &mut ScanStats, )

Like scan_line_into, additionally counting the work performed into stats.

Source

pub fn scan_buffer( &self, text: &str, emit: impl FnMut(usize, usize, &[Match]) -> bool, ) -> bool

Scans every line of text in one pass over the buffer and calls emit(line_start, line_end, matches) for each line with at least one match, in order; line_end excludes the terminator and trailing \rs, and the match ranges are relative to line_start, exactly as scan_line would report them for that line. Returns true when emit asked to stop.

With the vector strategy and no scan-mode finder the candidate search runs over the whole buffer and only lines holding a candidate are looked at, which is much cheaper than a call per line.

Source

pub fn scan_buffer_matches( &self, text: &str, emit: impl FnMut(usize, Range<usize>) -> bool, ) -> bool

Scans text like scan_buffer but hands every match to emit(finder_index, range) with a range into text, in the same order (by start, then finder), without resolving the lines around them; a caller that prints values alone skips that work. Returns true when emit asked to stop.

Source

pub fn scan_line_first(&self, line: &str) -> Option<Match>

Returns the same match as scan_line(line).into_iter().next(): the earliest-starting match, ties broken by the lowest finder index.

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.