Skip to main content

Worker

Struct Worker 

Source
pub struct Worker<T>
where T: SSS,
{ /* private fields */ }
Expand description

Worker: can instantiate, push, and get results. A view into computation.

Additionally, the worker can affect the computation via find and restart.

Implementations§

Source§

impl<T: SSS> Worker<T>

Source

pub fn default_format_fn<const QUOTE: bool>( &self, blank_format: impl Fn(&T) -> Cow<'_, str> + SSS, ) -> RenderFn<T>

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

Source§

impl<T: SSS> Worker<Indexed<T>>

Source

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

A convenience method to initialize data. Items are indexed starting from the current nucleo item count.

§Notes
  • Not concurrent.
  • Subsequent use of IndexedInjector should start from the returned count.
Source§

impl<T: Render + SSS> Worker<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.

Source§

impl<T> Worker<T>
where T: ColumnIndexable + SSS,

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 correspond to indices according to the relative order of the column names given to this function.

§Example
#[derive(Clone)]
pub struct RunAction {
    name: String,
    alias: String,
    desc: String
};

use matchmaker::{Matchmaker, Selector};
use matchmaker::nucleo::{Indexed, Worker, ColumnIndexable};

impl ColumnIndexable for RunAction {
    fn get_str(&self, i: usize) -> std::borrow::Cow<'_, str> {
        if i == 0 {
            &self.name
        } else if i == 1 {
            &self.alias
        } else {
            &self.desc
        }.into()
    }
}

pub fn make_mm(
    items: impl Iterator<Item = RunAction>,
) -> Matchmaker<Indexed<RunAction>, RunAction> {
    let worker = Worker::new_indexable(["name", "alias", "desc"]);
    worker.append(items);
    let selector = Selector::new(Indexed::identifier);
    Matchmaker::new(worker, selector)
}
Source§

impl<T> Worker<T>
where T: SSS,

Source

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

Column names must be distinct!

Source

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

Source

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

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

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

Source§

impl<T: SSS> Worker<T>

Source

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

§Notes
  • width is at least header width
Source

pub fn exact_column_match(&mut self, column: &str) -> Option<&T>

Source

pub fn format_with<'a>(&'a self, item: &'a T, col: &str) -> Option<Cow<'a, str>>

Auto Trait Implementations§

§

impl<T> Freeze for Worker<T>

§

impl<T> !RefUnwindSafe for Worker<T>

§

impl<T> Send for Worker<T>

§

impl<T> Sync for Worker<T>

§

impl<T> Unpin for Worker<T>

§

impl<T> UnsafeUnpin for Worker<T>

§

impl<T> !UnwindSafe for Worker<T>

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

Source§

fn take_from(&mut self, maybe: Option<T>)

Merge from maybe by taking.
Source§

fn clone_from(&mut self, maybe: &Option<T>)
where T: Clone,

Merge from maybe by cloning.
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> TransformExt for T

Source§

fn transform<Q>(self, transform: impl FnOnce(T) -> Q) -> Q

Source§

fn transform_if(self, condition: bool, transform: impl FnOnce(T) -> T) -> T

Example Read more
Source§

fn modify<Q>(self, modify: impl FnOnce(&mut T) -> Q) -> T

Source§

fn modify_if<Q>(self, condition: bool, modify: impl FnOnce(&mut T) -> Q) -> T

Example Read more
Source§

fn cmp_exch<'a, E>(&'a mut self, expected: E, new: T) -> bool
where &'a mut T: PartialEq<E>,

Example Read more
Source§

fn dbg(self) -> T
where T: Debug,

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> SSS for T
where T: Send + Sync + 'static,

Source§

impl<T> Selection for T