Skip to main content

IsamBuilder

Struct IsamBuilder 

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

Builder for creating or opening an Isam database with secondary indices.

Obtain a builder via Isam::builder. Call with_index for each secondary index, then create or open.

Implementations§

Source§

impl<K, V> IsamBuilder<K, V>
where K: Serialize + DeserializeOwned + Ord + Clone + Send + 'static, V: Serialize + DeserializeOwned + Clone + Send + 'static,

Source

pub fn with_index<E>(self, name: &str, _extractor: E) -> Self
where E: DeriveKey<V>,

Register a secondary index to be opened or created alongside the database.

name must be unique within a database. The extractor value is used only to infer the DeriveKey implementation — it is not stored.

After construction, obtain a typed handle for querying via Isam::index.

Source

pub fn rebuild_index(self, name: &str) -> Self

Mark a secondary index to be fully rebuilt from primary data during open.

The existing .sidb/.sidx files for name are deleted at open time and repopulated by scanning all primary records. The index must also be registered via with_index.

§When to use

Call this whenever the DeriveKey extractor logic has changed and the on-disk index is therefore stale. Without a rebuild, queries against a stale index will silently return incorrect results.

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

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

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

// Reopen and force a full rebuild of the "city" index.
let db = Isam::<u64, User>::builder()
    .with_index("city", CityIndex)
    .rebuild_index("city")
    .open(&path)
    .unwrap();
Source

pub fn create(self, path: impl AsRef<Path>) -> IsamResult<Isam<K, V>>

Create a new, empty database at path with the registered indices.

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

#[derive(Serialize, Deserialize, Clone)]
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>::builder()
    .with_index("city", CityIndex)
    .create(&path)
    .unwrap();
Source

pub fn open(self, path: impl AsRef<Path>) -> IsamResult<Isam<K, V>>

Open an existing database at path with the registered indices.

Secondary indices must be registered again on every open — the index name links the handle to the files on disk, but the extractor type is not persisted.

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

#[derive(Serialize, Deserialize, Clone)]
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>::builder()
    .with_index("city", CityIndex)
    .open(&path)
    .unwrap();
let city_idx = db.index::<CityIndex>("city");

Trait Implementations§

Source§

impl<K, V> Default for IsamBuilder<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for IsamBuilder<K, V>

§

impl<K, V> !RefUnwindSafe for IsamBuilder<K, V>

§

impl<K, V> !Send for IsamBuilder<K, V>

§

impl<K, V> !Sync for IsamBuilder<K, V>

§

impl<K, V> Unpin for IsamBuilder<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnsafeUnpin for IsamBuilder<K, V>

§

impl<K, V> !UnwindSafe for IsamBuilder<K, V>

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.