[][src]Struct retriever::queries::secondary_index::SecondaryIndex

pub struct SecondaryIndex<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized>(_)
where
    ChunkKey: BorrowedKey,
    ChunkKey::Owned: ValidKey,
    IndexKey: BorrowedKey,
    IndexKey::Owned: ValidKey,
    IndexKeys: Clone + Debug + Default + Eq + KeySet<'k, IndexKey>
;

A secondary index of the records in a Storage. You can attach as many SecondaryIndices to a given Storage as you want. Each SecondaryIndex will index each stored element under zero or more key values (but only one key type).

Type Parameters

  • ChunkKey: The chunk key type of the Storage.
  • Element: The element type of the Storage.
  • IndexKeys: A collection containing the type parameter IndexKey. This could be an Option, HashSet, etc.
  • IndexKey: The type of the secondary index key. This is the key you'll use to look up Elements via this SecondaryIndex.

How to choose IndexKeys and IndexKey.

SituationIndexKeysIndexKey
Index all emails marked "urgent"Option<()>()
Index automobiles by model yearOption<i32>i32
Index artwork by dominant colorHashSet<Color>Color

Panic

A SecondaryIndex is associated with exactly one storage. If you attempt to use a SecondaryIndex with a Storage other than the one it was initialized with, it will panic.

Methods

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey> where
    ChunkKey: BorrowedKey,
    ChunkKey::Owned: ValidKey,
    IndexKey: BorrowedKey,
    IndexKey::Owned: ValidKey,
    IndexKeys: Clone + Debug + Default + Eq + KeySet<'k, IndexKey>, 
[src]

pub fn new<ItemKey: ?Sized, F>(
    storage: &Storage<ChunkKey, ItemKey, Element>,
    f: F
) -> Self where
    ItemKey: BorrowedKey,
    ItemKey::Owned: ValidKey,
    Element: Record<ChunkKey, ItemKey>,
    F: Fn(&Element) -> Cow<IndexKeys> + Clone + Send + Sync + 'static, 
[src]

Create a new SecondaryIndex of a storage.

The indexing rule needs to return a collection of 0 or more IndexKeys for each Element. Collection types that will work well include: Option, HashSet, and BTreeSet.

Try to re-use SecondaryIndices as much as possible. If you drop a SecondaryIndex and then re-create it, the index has to be rebuilt, which might take a long time.

pub fn validate<ItemKey: ?Sized>(
    &self,
    parent: &Storage<ChunkKey, ItemKey, Element>
) where
    ItemKey: BorrowedKey,
    ItemKey::Owned: ValidKey,
    Element: Record<ChunkKey, ItemKey>, 
[src]

Panic if this storage is malformed or broken in any detectable way. This is a slow operation and you shouldn't use it unless you suspect a problem.

Trait Implementations

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> Clone for SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey> where
    ChunkKey: BorrowedKey,
    ChunkKey::Owned: ValidKey,
    IndexKey: BorrowedKey,
    IndexKey::Owned: ValidKey,
    IndexKeys: Clone + Debug + Default + Eq + KeySet<'k, IndexKey>, 
[src]

Auto Trait Implementations

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> Send for SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey> where
    IndexKeys: Send + Sync,
    <ChunkKey as ToOwned>::Owned: Send + Sync,
    <IndexKey as ToOwned>::Owned: Send + Sync

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> Sync for SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey> where
    IndexKeys: Send + Sync,
    <ChunkKey as ToOwned>::Owned: Send + Sync,
    <IndexKey as ToOwned>::Owned: Send + Sync

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> Unpin for SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey>

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> UnwindSafe for SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey>

impl<ChunkKey: ?Sized, Element, IndexKeys, IndexKey: ?Sized> RefUnwindSafe for SecondaryIndex<ChunkKey, Element, IndexKeys, IndexKey>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]