pub struct Matchmaker<T: PickerItem, S: Selection = T, C = ()> {
pub matcher: Option<Matcher>,
pub worker: Worker<T, C>,
/* private fields */
}Fields§
§matcher: Option<Matcher>§worker: Worker<T, C>Implementations§
Source§impl Matchmaker<Indexed<Segmented<String>>, Segmented<String>>
impl Matchmaker<Indexed<Segmented<String>>, Segmented<String>>
pub fn new_from_config( config: Config, ) -> (Self, SegmentedInjector<String, IndexedInjector<Segmented<String>, WorkerInjector<Indexed<Segmented<String>>>>>, MiscData)
Source§impl<T: PickerItem, S: Selection> Matchmaker<T, S>
impl<T: PickerItem, S: Selection> Matchmaker<T, S>
Sourcepub fn new(worker: Worker<T>, identifier: fn(&T) -> (u32, S)) -> Self
pub fn new(worker: Worker<T>, identifier: fn(&T) -> (u32, S)) -> Self
Examples found in repository?
examples/basic.rs (line 12)
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}Source§impl<T: PickerItem, S: Selection, C> Matchmaker<T, S, C>
impl<T: PickerItem, S: Selection, C> Matchmaker<T, S, C>
Sourcepub fn new_raw(
worker: Worker<T, C>,
identifier: fn(&T) -> (u32, S),
context: Arc<C>,
) -> Self
pub fn new_raw( worker: Worker<T, C>, identifier: fn(&T) -> (u32, S), context: Arc<C>, ) -> Self
For library use:
- create your worker (T -> Columns)
- instantiate a matcher (i.e. globally with lazylock)
- Determine your identifier
- Call mm.pick_with_matcher(&mut matcher)
pub fn config_binds(&mut self, bind_config: BindMap) -> &mut Self
pub fn config_render(&mut self, render_config: RenderConfig) -> &mut Self
pub fn config_preview( &mut self, preview_config: PreviewerConfig, ) -> Sender<PreviewMessage>
pub fn config_tui(&mut self, tui_config: TerminalConfig) -> &mut Self
pub fn config_exit(&mut self, exit_config: ExitConfig) -> &mut Self
pub fn register_event_handler<F, I>(&mut self, events: I, handler: F)where
F: Fn(EphemeralState<'_, T, S, C>, &Event) + Send + Sync + 'static,
I: IntoIterator<Item = Event>,
pub fn register_boxed_event_handler<I>(
&mut self,
events: I,
handler: DynamicMethod<T, S, C, Event>,
)where
I: IntoIterator<Item = Event>,
pub fn register_interrupt_handler<F>( &mut self, interrupt: Interrupt, handler: F, )
pub fn register_boxed_interrupt_handler( &mut self, variant: Interrupt, handler: DynamicMethod<T, S, C, Interrupt>, )
Sourcepub async fn pick(self) -> Result<impl IntoIterator<Item = S>>
pub async fn pick(self) -> Result<impl IntoIterator<Item = S>>
Examples found in repository?
examples/basic.rs (line 14)
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 async fn pick_with_matcher( self, matcher: &mut Matcher, ) -> Result<impl IntoIterator<Item = S>>
Trait Implementations§
Auto Trait Implementations§
impl<T, S, C> Freeze for Matchmaker<T, S, C>
impl<T, S = T, C = ()> !RefUnwindSafe for Matchmaker<T, S, C>
impl<T, S, C> Send for Matchmaker<T, S, C>
impl<T, S, C> Sync for Matchmaker<T, S, C>
impl<T, S, C> Unpin for Matchmaker<T, S, C>
impl<T, S = T, C = ()> !UnwindSafe for Matchmaker<T, S, 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