FzfParser

Struct FzfParser 

Source
pub struct FzfParser { /* private fields */ }
Available on crate features fzf-v1 or fzf-v2 only.
Expand description

The parser used to parse strings into FzfQuerys.

Queries can be parsed according to fzf’s extended-search mode via parse. If this is not desired, use parse_not_extended instead.

Implementations§

Source§

impl FzfParser

Source

pub fn new() -> Self

Creates a new FzfParser.

Source

pub fn parse<'a>(&'a mut self, query: &str) -> FzfQuery<'a>

Parses the given query string according to fzf’s extended-search mode.

In extended-search mode certain characters change how the query is matched in candidates.

In particular:

PatternMatches
foocandidates that fuzzy-match "foo"
'foocandidates that include "foo"
^foocandidates that start with "foo"
foo$candidates that end with "foo"
!foocandidates that don’t include "foo"
!^foocandidates that don’t start with "foo"
!foo$candidates that don’t end with "foo"

It’s also possible to query for multiple patterns by separating them with spaces or with the pipe character "|". A space acts as a logical AND operator, while a pipe character acts as a logical OR operator.

For example, the query "^main .c$ | .rs$" would only match candidates that start with "main" and end with either ".c" or ".rs". Spaces can be escaped with a backslash if they’re part of a pattern, e.g. "foo\ baz" will match "foo bar baz" but not "baz foo".

Note that like in fzf, but unlike in logical expressions, the pipe character (OR) has a higher precedence than the space character (AND), so that "foo bar | baz" gets parsed as "foo && (bar || baz)", and not as "(foo && bar) || baz";

If you want to treat all the characters in the query as fuzzy-matching, use parse_not_extended instead.

Source

pub fn parse_not_extended<'a>(&'a mut self, query: &str) -> FzfQuery<'a>

Parses the given query string without using fzf’s extended-search mode.

All the characters in the query string are used for fuzzy-matching, with no special meaning attached to any of them. This is equivalent to calling fzf with the --no-extended flag.

If you want to apply fzf’s extended-search mode to the query, parse it with parse instead.

§Examples
let mut fzf = FzfV2::new();
let mut parser = FzfParser::new();
let mut ranges = Vec::new();

let query = parser.parse_not_extended("^bar | baz$");

let distance =
    fzf.distance_and_ranges(query, "^foo bar | baz $ foo", &mut ranges);

// We expect a match since the characters in the query fuzzy-match the
// candidate.
//
// If we parsed the query by calling `parse` there wouldn't have been a
// match since the candidate doesn't start with `"bar"` nor does it end
// with `"baz"`.
assert!(distance.is_some());

assert_eq!(ranges, [0..1, 5..14, 15..16]);

Trait Implementations§

Source§

impl Clone for FzfParser

Source§

fn clone(&self) -> FzfParser

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FzfParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FzfParser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.