Skip to main content

FilterState

Struct FilterState 

Source
pub struct FilterState { /* private fields */ }
Expand description

A query and the candidates that match it, best first.

Candidates are strings to search; a match is a candidate’s index and the character positions that matched, for highlight. With an empty query every candidate matches, in order, except those hidden (set_hidden): a collapsed tree node’s children stay out of the list until something is typed.

Implementations§

Source§

impl FilterState

Source

pub fn new<I, S>(candidates: I) -> FilterState
where I: IntoIterator<Item = S>, S: Into<String>,

Filter candidates, with nothing typed yet.

Source

pub fn set_candidates<I, S>(&mut self, candidates: I)
where I: IntoIterator<Item = S>, S: Into<String>,

Replace the candidates and filter them again.

Source

pub fn candidates(&self) -> &[String]

Source

pub fn set_hidden(&mut self, hidden: Vec<bool>)

Leave these candidates out while the query is empty (true hides). Takes effect on the next refilter.

Source

pub fn set_tree(&mut self, parents: Option<Vec<Option<usize>>>)

Filter as a tree (#428): parents[i] is candidate i’s parent, and candidates come in tree order, each parent before its children. While a query is typed, what matches keeps its ancestors, so a match shows where it is: the list is the matches and their ancestors in tree order, the ancestors marked as context with nothing highlighted, and best is where the best match is. None goes back to a flat ranking. Takes effect on the next refilter.

Source

pub fn set_highlight_limits(&mut self, limits: Vec<usize>)

Highlight at most the first limits[i] characters of candidate i: for a candidate searched with more than its label (a description), so only the label highlights. Takes effect on the next refilter.

Source

pub fn query(&self) -> &str

What is typed.

Source

pub fn query_mut(&mut self) -> &mut String

The query, to edit in place; call refilter after.

Source

pub fn is_filtering(&self) -> bool

Source

pub fn set_query(&mut self, query: impl Into<String>)

Replace the query and filter again.

Source

pub fn push(&mut self, c: char)

Type c.

Source

pub fn push_str(&mut self, text: &str)

Type text (a paste: see pasted).

Source

pub fn pop(&mut self) -> bool

Delete the last character; false when there was none.

Source

pub fn clear(&mut self)

Clear the query.

Source

pub fn refilter(&mut self)

Match the candidates against the query again.

Source

pub fn is_context(&self, position: usize) -> bool

Whether the match at position is only there as an ancestor of a match (set_tree): drawn dim, not picked first.

Source

pub fn best(&self) -> Option<usize>

The position of the best match: the first, unless a tree keeps ancestors above it.

Source

pub fn matches(&self) -> &[(usize, Vec<usize>)]

The matches, best first: candidate indices and the positions to highlight.

Source

pub fn len(&self) -> usize

How many candidates match.

Source

pub fn is_empty(&self) -> bool

Source

pub fn index(&self, position: usize) -> Option<usize>

The candidate at position in the matches.

Source

pub fn position_of(&self, index: usize) -> Option<usize>

Where candidate index is in the matches, if it matches.

Trait Implementations§

Source§

impl Clone for FilterState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FilterState

Source§

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

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

impl Default for FilterState

Source§

fn default() -> Self

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

impl Eq for FilterState

Source§

impl PartialEq for FilterState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FilterState

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.