Scrolling Window Pattern Matcher
This crate provides a generic pattern matcher that operates over a scrolling window (queue) of items. Patterns can be defined as sequences of values, functions, or a mix of both. When a pattern matches, an optional user-defined callback is invoked. The matcher supports optional deduplication of matches.
Features
- Match patterns using values, functions, or both
- Optional deduplication of matches
- Support for overlapping matches
- Callback invocation on match
- No unnecessary trait bounds: PartialEq is only required for value-based patterns
Usage
use ;
let window = vec!;
let patterns = vec!;
let matcher = new;
let matches = matcher.find_matches;
assert!;
assert!;
Function-only Patterns
use ScrollingWindowFunctionPatternMatcherRef;
let window = vec!;
let patterns_fn: = vec!;
let matcher = new;
let matches = matcher.find_matches;
assert!;
assert!;
Deduplication and Overlapping Matches
Set deduplicate
to true
to avoid reporting the same match more than once.
Callback Example
use ;
let window = vec!;
let patterns = vec!;
let matcher = new;
let mut called = false;
let _ = matcher.find_matches;
assert!;
Edge Cases
- Empty window or patterns: returns no matches
- Patterns can be all values, all functions, or mixed
API
ScrollingWindowPatternMatcherRef::find_matches
: Use for value or mixed patterns (requires PartialEq for T)ScrollingWindowFunctionPatternMatcherRef::find_matches
: Use for function-only patterns (no trait bound required)
See the test module for more comprehensive examples and edge cases.