pub struct Matchmaker<T: MMItem, S: Selection = T, C = ()> {
pub worker: Worker<T, C>,
/* private fields */
}Expand description
The main entrypoint of the library. To use:
- create your worker (T -> Columns)
- Determine your identifier
- Instantiate this with Matchmaker::new_from_raw(..)
- Register your handlers 4.5 Start and connect your previewer
- Call mm.pick() or mm.pick_with_matcher(&mut matcher)
Fields§
§worker: Worker<T, C>Implementations§
Source§impl Matchmaker<Indexed<Segmented<String>>, Segmented<String>>
impl Matchmaker<Indexed<Segmented<String>>, Segmented<String>>
Sourcepub fn new_from_config(
config: Config,
matcher_config: MMConfig,
) -> (Self, ConfigInjector, OddEnds)
pub fn new_from_config( config: Config, matcher_config: MMConfig, ) -> (Self, ConfigInjector, OddEnds)
Creates a new Matchmaker from a config::Config.
Source§impl<T: MMItem, S: Selection> Matchmaker<T, S>
impl<T: MMItem, 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_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: MMItem, S: Selection, C> Matchmaker<T, S, C>
impl<T: MMItem, S: Selection, C> Matchmaker<T, S, C>
pub fn new_raw( worker: Worker<T, C>, identifier: fn(&T) -> (u32, S), context: Arc<C>, ) -> Self
Sourcepub fn get_controller(&self) -> UnboundedSender<Event>
pub fn get_controller(&self) -> UnboundedSender<Event>
The controller can be used to influence the event loop and by proxy the render loop. However, it’s role is not yet solidified.
Sourcepub fn connect_preview(&mut self, preview: Preview)
pub fn connect_preview(&mut self, preview: Preview)
The contents of the preview are displayed in a pane when picking.
Sourcepub fn config_binds(&mut self, bind_config: BindMap) -> &mut Self
pub fn config_binds(&mut self, bind_config: BindMap) -> &mut Self
Configure keybinds
Sourcepub fn config_render(&mut self, render_config: RenderConfig) -> &mut Self
pub fn config_render(&mut self, render_config: RenderConfig) -> &mut Self
Configure the UI
Sourcepub fn config_tui(&mut self, tui_config: TerminalConfig) -> &mut Self
pub fn config_tui(&mut self, tui_config: TerminalConfig) -> &mut Self
Configure the TUI
Sourcepub fn config_exit(&mut self, exit_config: ExitConfig) -> &mut Self
pub fn config_exit(&mut self, exit_config: ExitConfig) -> &mut Self
Configure exit conditions
Sourcepub fn register_event_handler<F, I>(&mut self, events: I, handler: F)where
F: Fn(&mut EphemeralState<'_, T, S, C>, &Event) + Send + Sync + 'static,
I: IntoIterator<Item = Event>,
pub fn register_event_handler<F, I>(&mut self, events: I, handler: F)where
F: Fn(&mut EphemeralState<'_, T, S, C>, &Event) + Send + Sync + 'static,
I: IntoIterator<Item = Event>,
Register a handler to listen on Events
Sourcepub fn register_boxed_event_handler<I>(
&mut self,
events: I,
handler: DynamicMethod<T, S, C, Event>,
)where
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>,
Register a boxed handler to listen on Events
Sourcepub fn register_interrupt_handler<F>(
&mut self,
interrupt: Interrupt,
handler: F,
)
pub fn register_interrupt_handler<F>( &mut self, interrupt: Interrupt, handler: F, )
Register a handler to listen on Interrupts
Sourcepub fn register_boxed_interrupt_handler(
&mut self,
variant: Interrupt,
handler: DynamicMethod<T, S, C, Interrupt>,
)
pub fn register_boxed_interrupt_handler( &mut self, variant: Interrupt, handler: DynamicMethod<T, S, C, Interrupt>, )
Register a boxed handler to listen on Interrupts
Sourcepub async fn pick_with_matcher(
self,
matcher: &mut Matcher,
) -> Result<Vec<S>, MatchError>
pub async fn pick_with_matcher( self, matcher: &mut Matcher, ) -> Result<Vec<S>, MatchError>
The main method of the Matchmaker. It starts listening for events and renders the TUI with ratatui. It successfully returns with all the selected items selected when the Accept action is received.
Sourcepub async fn pick(self) -> Result<Vec<S>, MatchError>
pub async fn pick(self) -> Result<Vec<S>, MatchError>
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_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}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