television_fuzzy::matcher

Struct Matcher

Source
pub struct Matcher<I>
where I: Sync + Send + Clone + 'static,
{ 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>
where I: Sync + Send + Clone + 'static,

Source

pub fn new(config: Config) -> Self

Create a new fuzzy matcher with the given configuration.

Source

pub fn tick(&mut self)

Tick the fuzzy matcher.

This should be called periodically to update the state of the matcher.

Source

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()
);
Source

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.

Source

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 MatchedItems 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
    // ...
}
Source

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.