sublime_fuzzy

Struct FuzzySearch

Source
pub struct FuzzySearch<'a> { /* private fields */ }
Expand description

Describes a fuzzy search. Alternative to best_match which allows for more configuration.

§Examples

Basic usage:

use sublime_fuzzy::{FuzzySearch, Scoring};

let scoring = Scoring::emphasize_word_starts();

let result = FuzzySearch::new("something", "Some Search Thing")
    .score_with(&scoring)
    .case_insensitive()
    .best_match();

assert!(result.is_some());

Implementations§

Source§

impl<'a> FuzzySearch<'a>

Source

pub fn new(query: &'a str, target: &'a str) -> Self

Creates a new search to match query in target.

Note that whitespace in query will be ignored.

Source

pub fn score_with(self, scoring: &'a Scoring) -> Self

Use custom scoring values.

If not specified will use Scoring::default().

Source

pub fn case_sensitive(self) -> Self

Only match query chars in the target string if case matches.

Scoring::bonus_match_case will not be applied if this is set (because a char match will always also be a case match).

Source

pub fn case_insensitive(self) -> Self

Ignore case when matching query chars in the target string.

If not only the char but also the case matches, Scoring::bonus_match_case will be added to the score. If that behavior is not wanted the bonus can be set to 0 with custom scoring.

Source

pub fn best_match(self) -> Option<Match>

Finds the best match of the query in the target string.

Always tries to match the full pattern. A partial match is considered invalid and will return None. Will also return None in case the query or target string are empty.

Auto Trait Implementations§

§

impl<'a> Freeze for FuzzySearch<'a>

§

impl<'a> RefUnwindSafe for FuzzySearch<'a>

§

impl<'a> Send for FuzzySearch<'a>

§

impl<'a> Sync for FuzzySearch<'a>

§

impl<'a> Unpin for FuzzySearch<'a>

§

impl<'a> UnwindSafe for FuzzySearch<'a>

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.