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 make_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: Render + SSS> 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/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}
More examples
Hide additional examples
examples/pick_1.rs (line 7)
4pub async fn mm_get<T: SSS + Render + Clone>(
5    items: impl IntoIterator<Item = T>,
6) -> Result<T, MatchError> {
7    let worker = Worker::new_single_column();
8    worker.append(items);
9    let selector = Selector::new(Indexed::identifier);
10    let mm = Matchmaker::new(worker, selector);
11
12    mm.pick_default().await.first()
13}
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 selector = Selector::new(Indexed::identifier);
11    let mm = Matchmaker::new(worker, selector);
12
13    match mm.pick_default().await {
14        Ok(v) => {
15            println!("{}", v[0]);
16        }
17        Err(err) => match err {
18            MatchError::Abort(1) => {
19                eprintln!("cancelled");
20            }
21            _ => {
22                eprintln!("Error: {err}");
23            }
24        },
25    }
26
27    Ok(())
28}
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/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}
More examples
Hide additional examples
examples/pick_1.rs (line 8)
4pub async fn mm_get<T: SSS + Render + Clone>(
5    items: impl IntoIterator<Item = T>,
6) -> Result<T, MatchError> {
7    let worker = Worker::new_single_column();
8    worker.append(items);
9    let selector = Selector::new(Indexed::identifier);
10    let mm = Matchmaker::new(worker, selector);
11
12    mm.pick_default().await.first()
13}
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 selector = Selector::new(Indexed::identifier);
11    let mm = Matchmaker::new(worker, selector);
12
13    match mm.pick_default().await {
14        Ok(v) => {
15            println!("{}", v[0]);
16        }
17        Err(err) => match err {
18            MatchError::Abort(1) => {
19                eprintln!("cancelled");
20            }
21            _ => {
22                eprintln!("Error: {err}");
23            }
24        },
25    }
26
27    Ok(())
28}
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 as displayed in the picker correspond to indices according to the relative order of the column names given to this function.

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 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: 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)

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> !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 maybe_take(&mut self, maybe: Option<T>)

Merge from maybe by taking.
Source§

fn maybe_clone(&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, 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