pub struct Nucleo<T: Sync + Send + 'static> {
pub pattern: MultiPattern,
/* private fields */
}Expand description
A high level matcher worker that quickly computes matches in a background threadpool.
§Example
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread;
use ncp_engine::{Config, Nucleo};
static NEEDS_UPDATE: AtomicBool = AtomicBool::new(false);
// initialize a new matcher with default configuration and one column
let matcher = Nucleo::new(
Config::DEFAULT,
Arc::new(|| NEEDS_UPDATE.store(true, Ordering::Relaxed)),
None,
1
);
// get a handle to add items to the matcher
let injector = matcher.injector();
// add items to the matcher
thread::spawn(move || {
injector.push("Hello, world!".to_string(), |s, cols| {
cols[0] = (&**s).into();
});
});Fields§
§pattern: MultiPatternThe pattern matched by this matcher.
To update the match pattern, use MultiPattern::reparse. Note that
the matcher worker will only become aware of the new pattern after a
call to tick.
Implementations§
Source§impl<T: Sync + Send + 'static> Nucleo<T>
impl<T: Sync + Send + 'static> Nucleo<T>
Sourcepub fn new(
config: Config,
notify: Arc<dyn Fn() + Sync + Send>,
num_threads: Option<usize>,
columns: u32,
) -> Self
pub fn new( config: Config, notify: Arc<dyn Fn() + Sync + Send>, num_threads: Option<usize>, columns: u32, ) -> Self
Constructs a new nucleo worker threadpool with the provided config.
notify is called whenever new information is available and
tick should be called. Note that notify is not
debounced; that should be handled by the downstream crate (for example,
debouncing to only redraw at most every 1/60 seconds).
If None is passed for the number of worker threads, nucleo will use
one thread per hardware thread.
Nucleo can match items with multiple orthogonal properties. columns
indicates how many matching columns each item (and the pattern) has. The
number of columns cannot be changed after construction.
Sourcepub fn active_injectors(&self) -> usize
pub fn active_injectors(&self) -> usize
Returns the total number of active injectors.
Sourcepub fn snapshot(&self) -> &Snapshot<T>
pub fn snapshot(&self) -> &Snapshot<T>
Returns a snapshot of the current matcher state.
This method is very cheap and can be called every time a snapshot is required. The
snapshot will not change unless tick is called.
Sourcepub fn injector(&self) -> Injector<T>
pub fn injector(&self) -> Injector<T>
Returns an injector that can be used for adding candidates to the matcher.
Sourcepub fn restart(&mut self, clear_snapshot: bool)
pub fn restart(&mut self, clear_snapshot: bool)
Restart the the item stream. Removes all items and disconnects all
previously created injectors from this instance. If clear_snapshot
is true then all items and matched are removed from the Snapshot
immediately. Otherwise the snapshot will keep the current matches until
the matcher has run again.
§Note
The injectors will continue to function but they will not affect this instance anymore. The old items will only be dropped when all injectors were dropped.
Sourcepub fn update_config(&mut self, config: Config)
pub fn update_config(&mut self, config: Config)
Update the internal configuration.
Sourcepub fn sort_results(&mut self, sort_results: bool)
pub fn sort_results(&mut self, sort_results: bool)
Set whether the matcher should sort search results by score after matching. Defaults to true.
Sourcepub fn reverse_items(&mut self, reverse_items: bool)
pub fn reverse_items(&mut self, reverse_items: bool)
Set whether the matcher should reverse the order of the input. Defaults to false.
Sourcepub fn tick(&mut self, timeout: u64) -> Status
pub fn tick(&mut self, timeout: u64) -> Status
Update the internal state to reflect any changes from the background worker threads.
This is the main way to interact with the matcher, and should be called
regularly (for example each time a frame is rendered). To avoid excessive
redraws this method will wait timeout milliseconds for the
worker thread to finish. It is recommend to set the timeout to 10ms.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Nucleo<T>
impl<T> !RefUnwindSafe for Nucleo<T>
impl<T> Send for Nucleo<T>
impl<T> Sync for Nucleo<T>
impl<T> Unpin for Nucleo<T>
impl<T> !UnwindSafe for Nucleo<T>
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
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>
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>
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