pub struct Matcher<I>{
pub total_item_count: u32,
pub matched_item_count: u32,
pub status: Status,
pub last_pattern: String,
/* private fields */
}
Expand description
A fuzzy matcher that can be used to match items of type I
.
I
should be Sync
, Send
, Clone
, and 'static
.
This is a wrapper around the Nucleo
fuzzy matcher that only matches
on a single dimension.
The matcher can be used to find items that match a given pattern and to retrieve the matched items as well as the indices of the matched characters.
Fields§
§total_item_count: u32
The current total number of items in the matcher.
matched_item_count: u32
The current number of matched items in the matcher.
status: Status
The current status of the matcher.
last_pattern: String
The last pattern that was matched against.
Implementations§
Source§impl<I> Matcher<I>
impl<I> Matcher<I>
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Tick the fuzzy matcher.
This should be called periodically to update the state of the matcher.
Sourcepub fn injector(&self) -> Injector<I>
pub fn injector(&self) -> Injector<I>
Get an injector that can be used to push items into the fuzzy matcher.
This can be used at any time to push items into the fuzzy matcher.
§Example
use television_fuzzy::matcher::{config::Config, Matcher};
let config = Config::default();
let matcher = Matcher::new(config);
let injector = matcher.injector();
injector.push(
("some string", 3, "some other string"),
// Say we want to match against the third element of the tuple
|s, cols| cols[0] = s.2.into()
);
Sourcepub fn find(&mut self, pattern: &str)
pub fn find(&mut self, pattern: &str)
Find items that match the given pattern.
This should be called whenever the pattern changes.
The Matcher
will keep track of the last pattern and only reparse the
pattern if it has changed, allowing for more efficient matching when
self.last_pattern
is a prefix of the new pattern
.
Sourcepub fn results(&mut self, num_entries: u32, offset: u32) -> Vec<MatchedItem<I>>
pub fn results(&mut self, num_entries: u32, offset: u32) -> Vec<MatchedItem<I>>
Get the matched items.
This should be called to retrieve the matched items after calling
find
.
The num_entries
parameter specifies the number of entries to return,
and the offset
parameter specifies the offset of the first entry to
return.
The returned items are MatchedItem
s that contain the matched item, the
dimension against which it was matched, represented as a string, and the
indices of the matched characters.
§Example
use television_fuzzy::matcher::{config::Config, Matcher};
let config = Config::default();
let mut matcher: Matcher<String> = Matcher::new(config);
matcher.find("some pattern");
let results = matcher.results(10, 0);
for item in results {
println!("{:?}", item);
// Do something with the matched item
// ...
// Do something with the matched indices
// ...
}
Sourcepub fn get_result(&self, index: u32) -> Option<MatchedItem<I>>
pub fn get_result(&self, index: u32) -> Option<MatchedItem<I>>
Get a single matched item.
§Example
use television_fuzzy::matcher::{config::Config, Matcher};
let config = Config::default();
let mut matcher: Matcher<String> = Matcher::new(config);
matcher.find("some pattern");
if let Some(item) = matcher.get_result(0) {
// Do something with the matched item
// ...
}
Auto Trait Implementations§
impl<I> Freeze for Matcher<I>
impl<I> !RefUnwindSafe for Matcher<I>
impl<I> Send for Matcher<I>
impl<I> Sync for Matcher<I>
impl<I> Unpin for Matcher<I>
impl<I> !UnwindSafe for Matcher<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more