pub struct Worker<T, C = ()>where
T: PickerItem,{ /* 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: PickerItem,
impl<T, C> Worker<T, C>where
T: PickerItem,
pub fn new( columns: impl IntoIterator<Item = Column<T, C>>, default_column: usize, context: C, ) -> Self
pub fn injector(&self) -> WorkerInjector<T, C>
pub fn results( &mut self, start: u32, end: u32, matcher: &mut Matcher, ) -> (Vec<(Vec<Text<'_>>, &T, u16)>, Vec<u16>, Status)
pub fn find(&mut self, line: &str)
pub fn shutdown(&mut self)
pub fn restart(&mut self, clear_snapshot: bool)
pub fn get_nth(&self, n: u32) -> Option<&T>
pub fn new_snapshot(nucleo: &mut Nucleo<T>) -> (&Snapshot<T>, Status)
pub fn raw_results( &self, ) -> impl ExactSizeIterator<Item = &T> + DoubleEndedIterator + '_
Source§impl<T: PickerItem> Worker<T>
impl<T: PickerItem> Worker<T>
Source§impl<T: Render + PickerItem> Worker<Indexed<T>>
impl<T: Render + PickerItem> Worker<Indexed<T>>
Sourcepub fn new_single() -> Self
pub fn new_single() -> Self
Examples found in repository?
More examples
examples/basic.rs (line 8)
5async fn main() -> Result<()> {
6 let items = vec!["item1", "item2", "item3"];
7
8 let worker = Worker::new_single();
9 worker.append(items);
10 let identifier = Worker::clone_identifier;
11
12 let mm = Matchmaker::new(worker, identifier);
13
14 match mm.pick().await {
15 Ok(iter) => {
16 for s in iter {
17 println!("{s}");
18 }
19 }
20 Err(err) => {
21 if let Some(e) = err.downcast_ref::<MatchmakerError>()
22 && matches!(e, MatchmakerError::Abort(1))
23 {
24 eprintln!("cancelled");
25 } else {
26 eprintln!("Error: {err}");
27 }
28 }
29 }
30
31 Ok(())
32}Sourcepub fn append(&self, items: impl IntoIterator<Item = T>) -> u32
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?
More examples
examples/basic.rs (line 9)
5async fn main() -> Result<()> {
6 let items = vec!["item1", "item2", "item3"];
7
8 let worker = Worker::new_single();
9 worker.append(items);
10 let identifier = Worker::clone_identifier;
11
12 let mm = Matchmaker::new(worker, identifier);
13
14 match mm.pick().await {
15 Ok(iter) => {
16 for s in iter {
17 println!("{s}");
18 }
19 }
20 Err(err) => {
21 if let Some(e) = err.downcast_ref::<MatchmakerError>()
22 && matches!(e, MatchmakerError::Abort(1))
23 {
24 eprintln!("cancelled");
25 } else {
26 eprintln!("Error: {err}");
27 }
28 }
29 }
30
31 Ok(())
32}pub fn clone_identifier(item: &Indexed<T>) -> (u32, T)where
T: Clone,
Source§impl<T> Worker<T>where
T: ColumnIndexable + PickerItem,
impl<T> Worker<T>where
T: ColumnIndexable + PickerItem,
pub fn new_indexable<I, S>(column_names: I) -> Self
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>
impl<T, C> Sync for Worker<T, C>
impl<T, C> Unpin for Worker<T, C>
impl<T, C = ()> !UnwindSafe for Worker<T, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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