SecondaryIndexHandle

Struct SecondaryIndexHandle 

Source
pub struct SecondaryIndexHandle<K, V, SK> { /* private fields */ }
Expand description

An opaque handle to a registered secondary index, used for point lookups.

Obtained from Isam::register_secondary_index.

Implementations§

Source§

impl<K, V, SK> SecondaryIndexHandle<K, V, SK>

Source

pub fn lookup( &self, txn: &mut Transaction<'_, K, V>, sk: &SK, ) -> IsamResult<Vec<(K, V)>>

Return all (primary_key, value) pairs whose secondary key equals sk.

Results are returned in insertion order (not key order). For a non-existent secondary key the result is an empty Vec.

§Example
use serde::{Serialize, Deserialize};
use highlandcows_isam::{Isam, DeriveKey};

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
struct User { name: String, city: String }

struct CityIndex;
impl DeriveKey<User> for CityIndex {
    type Key = String;
    fn derive(u: &User) -> String { u.city.clone() }
}

let db: Isam<u64, User> = Isam::create(&path).unwrap();
let city_idx = db.register_secondary_index("city", CityIndex).unwrap();

let mut txn = db.begin_transaction().unwrap();
db.insert(&mut txn, 1, &User { name: "Alice".into(), city: "London".into() }).unwrap();
db.insert(&mut txn, 2, &User { name: "Bob".into(),   city: "London".into() }).unwrap();
db.insert(&mut txn, 3, &User { name: "Carol".into(), city: "Paris".into()  }).unwrap();
txn.commit().unwrap();

let mut txn = db.begin_transaction().unwrap();
let mut londoners = city_idx.lookup(&mut txn, &"London".to_string()).unwrap();
londoners.sort_by_key(|(pk, _)| *pk);
assert_eq!(londoners[0].0, 1);
assert_eq!(londoners[1].0, 2);
assert_eq!(city_idx.lookup(&mut txn, &"Berlin".to_string()).unwrap(), vec![]);
txn.commit().unwrap();

Auto Trait Implementations§

§

impl<K, V, SK> Freeze for SecondaryIndexHandle<K, V, SK>

§

impl<K, V, SK> RefUnwindSafe for SecondaryIndexHandle<K, V, SK>

§

impl<K, V, SK> Send for SecondaryIndexHandle<K, V, SK>

§

impl<K, V, SK> Sync for SecondaryIndexHandle<K, V, SK>

§

impl<K, V, SK> Unpin for SecondaryIndexHandle<K, V, SK>

§

impl<K, V, SK> UnwindSafe for SecondaryIndexHandle<K, V, SK>

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