Struct mmtkvdb::DbBuilder

source ·
pub struct DbBuilder<K: ?Sized, V: ?Sized, C, N> { /* private fields */ }
Expand description

Options for opening a database

This struct follows the builder pattern. Start with DbBuilder::new and pass completed builder by (shared) reference to EnvRo::open_db or EnvRw::create_db to open or create a database.

Caveats / Safety

When opening an already existing database, all options must be compatible with the previously used options. It has be be ensured by the caller that this is true. Thus EnvRo::open_db and EnvRw::create_db are marked as unsafe.

DbBuilder::name has to be called last (after setting all other options). This is due to some restrictions regarding const fns. A compiler error will be reported if the methods are invoked in the wrong order.

Type arguments

The type arguments K, V, and C reflect the type used for keys and values, and whether duplicate keys are allowed (C being KeysUnique or KeysDuplicate), respectively.

The fourth type parameter N determines if a name (or the unnamed database) has been set, or if a name must be selected yet. N is () if no database name has been selected yet. Once a name has been selected, you can use the type alias DbSpec<K, V, C> to refer to the completed builder.

Example

// question mark operator may return with `std::io::Error`
use mmtkvdb::{self as kv, Txn as _};
use tempfile::tempdir;
let location = tempdir()?;
let env_builder = kv::EnvBuilder::new().dir(location.path()).max_dbs(1);
let mut env_rw = unsafe { env_builder.open_rw() }?;
let db_opts = kv::DbBuilder::new()
    .key_type::<str>()
    .value_type::<i32>()
    .name("account_balance");
let db = unsafe { env_rw.create_db(&db_opts) }?;

Implementations§

source§

impl DbBuilder<[u8], [u8], KeysUnique, ()>

source

pub const fn new() -> Self

Default options for database

source§

impl<K: ?Sized, V: ?Sized, C> DbBuilder<K, V, C, ()>where
C: Constraint,

source

pub const fn keys_unique(self) -> DbBuilder<K, V, KeysUnique, ()>

Clear dupsort option (also clears reversedup option)

See DbBuilder::keys_duplicate for setting dupsort option and DbBuilder::has_duplicate_keys for getting current state of flag.

source

pub const fn keys_duplicate(self) -> DbBuilder<K, V, KeysDuplicate, ()>

Set dupsort option

Note: Using this option will put an additional constraint on the size of each value stored in the database (see EnvRo::max_keysize).

See DbBuilder::keys_unique for clearing dupsort option and DbBuilder::has_duplicate_keys for getting current state of flag.

source

pub const fn key_type<T>(self) -> DbBuilder<T, V, C, ()>where
T: ?Sized + Storable,

Set stored key type

source

pub const fn value_type<T>(self) -> DbBuilder<K, T, C, ()>where
T: ?Sized + Storable,

Set stored value type

source§

impl<K: ?Sized, V: ?Sized, C, N> DbBuilder<K, V, C, N>where
C: Constraint,

source

pub const fn get_reversekey(&self) -> bool

Get reversekey option

source

pub const fn reversekey(self, flag: bool) -> Self

Set or clear reversekey option

source

pub fn unnamed(self) -> DbSpec<K, V, C>

Use unnamed database

Should be used as last builder method because some other builder methods are not available anymore after calling this method.

source

pub fn name<T: Into<Vec<u8>>>(self, name: T) -> DbSpec<K, V, C>

Use named database (name must not contain a null byte)

Should be used as last builder method because some other builder methods are not available anymore after calling this method.

source

pub fn strip_name<T: Into<Vec<u8>>>(self) -> DbBuilder<K, V, C, ()>

Remove name information

NOTE: This does not select the unnamed database. To select the unnamed database, use DbBuilder::unnamed.

source§

impl<K: ?Sized, V: ?Sized, C: Constraint, N> DbBuilder<K, V, C, N>

source

pub fn has_duplicate_keys(&self) -> bool

Returns true if duplicate keys are allowed (i.e. is dupsort option set?)

See DbBuilder::keys_unique and DbBuilder::keys_duplicate.

source§

impl<K: ?Sized, V: ?Sized, N> DbBuilder<K, V, KeysDuplicate, N>

source

pub const fn get_reversedup(&self) -> bool

Get reversedup option

source

pub const fn reversedup(self, flag: bool) -> Self

Set or clear reversedup option

Trait Implementations§

source§

impl<K: Clone + ?Sized, V: Clone + ?Sized, C: Clone, N: Clone> Clone for DbBuilder<K, V, C, N>

source§

fn clone(&self) -> DbBuilder<K, V, C, N>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<K: Debug + ?Sized, V: Debug + ?Sized, C: Debug, N: Debug> Debug for DbBuilder<K, V, C, N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K: ?Sized, V: ?Sized, C, N> RefUnwindSafe for DbBuilder<K, V, C, N>where
C: RefUnwindSafe,
N: RefUnwindSafe,

§

impl<K: ?Sized, V: ?Sized, C, N> Send for DbBuilder<K, V, C, N>where
C: Send,
N: Send,

§

impl<K: ?Sized, V: ?Sized, C, N> Sync for DbBuilder<K, V, C, N>where
C: Sync,
N: Sync,

§

impl<K: ?Sized, V: ?Sized, C, N> Unpin for DbBuilder<K, V, C, N>where
C: Unpin,
N: Unpin,

§

impl<K: ?Sized, V: ?Sized, C, N> UnwindSafe for DbBuilder<K, V, C, N>where
C: UnwindSafe,
N: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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> ToOwned for Twhere
T: Clone,

§

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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.