pub static MATCHER: LazyMutex<Matcher>
Expand description
A lazy-initialized nucleo matcher used for conveniently computing match indices.
This is used to lazily initialize a nucleo matcher (which pre-allocates quite a bit of memory upfront which can be expensive at initialization).
This matcher is used as a convenience for computing match indices on a subset of matched items.
§Example
ⓘ
use television-fuzzy::matcher::{lazy::MATCHER, matched_item::MatchedItem};
let snapshot = channel_matcher.snapshot();
let mut col_indices = vec![];
let mut matcher = MATCHER.lock();
snapshot
.matched_items(..)
.map(move |item| {
snapshot.pattern().column_pattern(0).indices(
item.matcher_columns[0].slice(..),
&mut matcher,
&mut col_indices,
);
col_indices.sort_unstable();
col_indices.dedup();
let indices = col_indices.drain(..);
let matched_string = item.matcher_columns[0].to_string();
MatchedItem {
inner: item.data.clone(),
matched_string,
match_indices: indices.map(|i| (i, i + 1)).collect(),
}
})
.collect();