Skip to main content

StreamingMatcher

Struct StreamingMatcher 

Source
pub struct StreamingMatcher<'r> { /* private fields */ }
Expand description

A streaming matcher for incremental fuzzy regex matching.

This type maintains state across multiple feed() calls, allowing matches to span chunk boundaries.

§Example

use fuzzy_regex::FuzzyRegex;

let re = FuzzyRegex::new("(?:hello){e<=1}").unwrap();
let mut stream = re.stream();

// Process data in chunks
for chunk in [b"hel".as_slice(), b"lo world".as_slice()] {
    for m in stream.feed(chunk) {
        println!("Found match at offset {}", m.start());
    }
}

Implementations§

Source§

impl<'r> StreamingMatcher<'r>

Source

pub fn feed(&mut self, chunk: &[u8]) -> FeedMatches<'_>

Feed a chunk of bytes into the matcher.

Returns an iterator over matches found in this chunk (including matches that span from the previous chunk).

Source

pub fn finish(&mut self) -> Option<StreamingMatch>

Signal end of stream and return any final match.

Call this after all data has been fed to handle matches at the end of the stream.

Source

pub fn reset(&mut self)

Reset the matcher state for reuse.

Source

pub fn position(&self) -> usize

Get the current position in the stream (total bytes processed).

Source

pub fn search_reader<R: Read>(self, reader: R) -> ReaderMatches<'r, R>

Process a reader, yielding matches.

Reads the reader in chunks and yields matches as they are found.

§Example
use fuzzy_regex::FuzzyRegex;
use std::fs::File;
use std::io::BufReader;

let re = FuzzyRegex::new("(?:hello){e<=1}").unwrap();
let mut stream = re.stream();

let file = File::open("large_file.txt").unwrap();
for m in stream.search_reader(BufReader::new(file)) {
    println!("Match at {}-{}", m.start(), m.end());
}

Auto Trait Implementations§

§

impl<'r> Freeze for StreamingMatcher<'r>

§

impl<'r> !RefUnwindSafe for StreamingMatcher<'r>

§

impl<'r> !Send for StreamingMatcher<'r>

§

impl<'r> !Sync for StreamingMatcher<'r>

§

impl<'r> Unpin for StreamingMatcher<'r>

§

impl<'r> UnsafeUnpin for StreamingMatcher<'r>

§

impl<'r> !UnwindSafe for StreamingMatcher<'r>

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.