pub struct Injector<T> { /* private fields */ }Expand description
A handle that allows adding new items to a Nucleo worker.
An Injector is internally reference counted and can be cheaply
cloned and sent across threads.
Implementations§
Source§impl<T> Injector<T>
impl<T> Injector<T>
Sourcepub fn push(
&self,
value: T,
fill_columns: impl FnOnce(&T, &mut [Utf32String]),
) -> u32
pub fn push( &self, value: T, fill_columns: impl FnOnce(&T, &mut [Utf32String]), ) -> u32
Appends an element to the list of match candidates.
This function is lock-free and wait-free. The returned u32 is the internal index which
has been assigned to the provided value and is guaranteed to be valid unless
Nucleo::restart has been called.
The fill_columns closure is called to generate the representation of the pushed value
within the matcher engine. The first argument is a reference to the provided value, and the
second argument is a slice where each entry corresponds to a column within the Nucleo
instance from which this Injector was created.
§Example
If the matcher has exactly one column and the item type T is a String, an appropriate
fill_columns closure might look like
let fill_columns = |s: &String, cols: &mut [Utf32String]| {
cols[0] = (&**s).into();
};Sourcepub fn extend_exact<I>(
&self,
values: I,
fill_columns: impl Fn(&T, &mut [Utf32String]),
)where
I: IntoIterator<Item = T> + ExactSizeIterator,
pub fn extend_exact<I>(
&self,
values: I,
fill_columns: impl Fn(&T, &mut [Utf32String]),
)where
I: IntoIterator<Item = T> + ExactSizeIterator,
Appends multiple elements to the list of matched items. This function is lock-free and wait-free.
You should favor this function over push if at least one of the following is true:
- the number of items you’re adding can be computed beforehand and is typically larger than 1k
- you’re able to batch incoming items
- you’re adding items from multiple threads concurrently (this function results in less contention)
Sourcepub fn injected_items(&self) -> u32
pub fn injected_items(&self) -> u32
Returns the total number of items injected in the matcher.
This may not match the number of items in the match snapshot if the matcher is still running.
Sourcepub unsafe fn get_unchecked(&self, index: u32) -> Item<'_, T>
pub unsafe fn get_unchecked(&self, index: u32) -> Item<'_, T>
Returns a reference to the item at the given index.
§Safety
Item at index must be initialized. That means you must have observed
push returning this value or get returning Some for this value.
Just because a later index is initialized doesn’t mean that this index
is initialized
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Injector<T>
impl<T> !RefUnwindSafe for Injector<T>
impl<T> Send for Injector<T>
impl<T> Sync for Injector<T>
impl<T> Unpin for Injector<T>
impl<T> !UnwindSafe for Injector<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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