Matchmaker

Struct Matchmaker 

Source
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>>

Source§

impl<T: PickerItem, S: Selection> Matchmaker<T, S>

Source

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>

Source

pub fn new_raw( worker: Worker<T, C>, identifier: fn(&T) -> (u32, S), context: Arc<C>, ) -> Self

For library use:

  1. create your worker (T -> Columns)
  2. instantiate a matcher (i.e. globally with lazylock)
  3. Determine your identifier
  4. Call mm.pick_with_matcher(&mut matcher)
Source

pub fn config_binds(&mut self, bind_config: BindMap) -> &mut Self

Source

pub fn config_render(&mut self, render_config: RenderConfig) -> &mut Self

Source

pub fn config_preview( &mut self, preview_config: PreviewerConfig, ) -> Sender<PreviewMessage>

Source

pub fn config_tui(&mut self, tui_config: TerminalConfig) -> &mut Self

Source

pub fn config_exit(&mut self, exit_config: ExitConfig) -> &mut Self

Source

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>,

Source

pub fn register_boxed_event_handler<I>( &mut self, events: I, handler: DynamicMethod<T, S, C, Event>, )
where I: IntoIterator<Item = Event>,

Source

pub fn register_interrupt_handler<F>( &mut self, interrupt: Interrupt, handler: F, )
where F: Fn(EphemeralState<'_, T, S, C>, &Interrupt) + Send + Sync + 'static,

Source

pub fn register_boxed_interrupt_handler( &mut self, variant: Interrupt, handler: DynamicMethod<T, S, C, Interrupt>, )

Source

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}
Source

pub async fn pick_with_matcher( self, matcher: &mut Matcher, ) -> Result<impl IntoIterator<Item = S>>

Trait Implementations§

Source§

impl<T: PickerItem + Debug, S: Selection + Debug, C: Debug> Debug for Matchmaker<T, S, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>
where C: Sync + Send,

§

impl<T, S, C> Sync for Matchmaker<T, S, C>
where C: Sync + Send,

§

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