Injector

Struct Injector 

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

Source

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();
};
Source

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

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.

Source

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

Source

pub fn get(&self, index: u32) -> Option<Item<'_, T>>

Returns a reference to the element at the given index.

Trait Implementations§

Source§

impl<T> Clone for Injector<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.