Worker

Struct Worker 

Source
pub struct Worker<T, C = ()>
where T: MMItem,
{ /* private fields */ }
Expand description

Worker: can instantiate, can push, can get lines and get nth, a view into computation

Implementations§

Source§

impl<T, C> Worker<T, C>
where T: MMItem,

Source

pub fn new( columns: impl IntoIterator<Item = Column<T, C>>, default_column: usize, context: C, ) -> Self

Source

pub fn injector(&self) -> WorkerInjector<T, C>

Source

pub fn find(&mut self, line: &str)

Source

pub fn shutdown(&mut self)

Source

pub fn restart(&mut self, clear_snapshot: bool)

Source

pub fn get_nth(&self, n: u32) -> Option<&T>

Source

pub fn new_snapshot(nucleo: &mut Nucleo<T>) -> (&Snapshot<T>, Status)

Source

pub fn raw_results( &self, ) -> impl ExactSizeIterator<Item = &T> + DoubleEndedIterator + '_

Source

pub fn counts(&self) -> (u32, u32)

matched item count, total item count

Source§

impl<T: MMItem, C> Worker<T, C>

Source

pub fn results( &mut self, start: u32, end: u32, width_limits: &[u16], highlight_style: Style, matcher: &mut Matcher, ) -> (WorkerResults<'_, T>, Vec<u16>, Status)

Source§

impl<T: MMItem> Worker<T>

Source

pub fn make_format_fn<const QUOTE: bool>( &self, blank_format: impl Fn(&T) -> &str + Send + Sync + 'static, ) -> RenderFn<T>

Returns a function which templates a string given an item using the column functions

Source§

impl<T: Render + MMItem> Worker<Indexed<T>>

Source

pub fn new_single_column() -> Self

Create a new worker over items which are displayed in the picker as exactly their as_str representation.

Examples found in repository?
examples/frecency.rs (line 5)
4fn main() -> Result<()> {
5    let worker = Worker::new_single_column();
6    let items = vec!["item1", "item2", "item3"];
7    worker.append(items);
8
9    Ok(())
10}
More examples
Hide additional examples
examples/ripgrep.rs (line 5)
4fn main() -> Result<()> {
5    let worker = Worker::new_single_column();
6    let items = vec!["item1", "item2", "item3"];
7    worker.append(items);
8
9    Ok(())
10}
examples/basic.rs (line 8)
5async fn main() -> Result<()> {
6    let items = vec!["item1", "item2", "item3"];
7
8    let worker = Worker::new_single_column();
9    worker.append(items);
10    let identifier = Indexed::identifier;
11
12    let mm = Matchmaker::new(worker, identifier);
13
14    match mm.pick().await {
15        Ok(v) => {
16            println!("{}", v[0]);
17        }
18        Err(err) => {
19            match err {
20                MatchError::Abort(1) => {
21                    eprintln!("cancelled");
22                }
23                _ => {
24                    eprintln!("Error: {err}");
25                }
26            }
27        }
28    }
29
30    Ok(())
31}
Source

pub fn append(&self, items: impl IntoIterator<Item = T>) -> u32

A convenience method to initialize data. Note that it is clearly unsound to use this concurrently with other workers, or to subsequently push with an IndexedInjector.

Examples found in repository?
examples/frecency.rs (line 7)
4fn main() -> Result<()> {
5    let worker = Worker::new_single_column();
6    let items = vec!["item1", "item2", "item3"];
7    worker.append(items);
8
9    Ok(())
10}
More examples
Hide additional examples
examples/ripgrep.rs (line 7)
4fn main() -> Result<()> {
5    let worker = Worker::new_single_column();
6    let items = vec!["item1", "item2", "item3"];
7    worker.append(items);
8
9    Ok(())
10}
examples/basic.rs (line 9)
5async fn main() -> Result<()> {
6    let items = vec!["item1", "item2", "item3"];
7
8    let worker = Worker::new_single_column();
9    worker.append(items);
10    let identifier = Indexed::identifier;
11
12    let mm = Matchmaker::new(worker, identifier);
13
14    match mm.pick().await {
15        Ok(v) => {
16            println!("{}", v[0]);
17        }
18        Err(err) => {
19            match err {
20                MatchError::Abort(1) => {
21                    eprintln!("cancelled");
22                }
23                _ => {
24                    eprintln!("Error: {err}");
25                }
26            }
27        }
28    }
29
30    Ok(())
31}
Source§

impl<T> Worker<T>

Source

pub fn new_indexable<I, S>(column_names: I) -> Self
where I: IntoIterator<Item = S>, S: Into<Arc<str>>,

Create a new worker over indexable items, whose columns as displayed in the picker correspond to indices according to the relative order of the column names given to this function.

Auto Trait Implementations§

§

impl<T, C> Freeze for Worker<T, C>

§

impl<T, C = ()> !RefUnwindSafe for Worker<T, C>

§

impl<T, C> Send for Worker<T, C>
where C: Sync + Send,

§

impl<T, C> Sync for Worker<T, C>
where C: Sync + Send,

§

impl<T, C> Unpin for Worker<T, C>

§

impl<T, C = ()> !UnwindSafe for Worker<T, C>

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

impl<T> MMItem for T
where T: Sync + Send + 'static,