Expand description
Options for opening a database
This struct follows the builder pattern. Start with DbOptions::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
.
DbOptions::name
has to be called last (after setting all other
options). This is due to some restrictions regarding const fn
s.
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 determines if a name has been set (or the unnamed database has been selected), or if a name (or unnamed database) must be selected yet.
Example
use mmtkvdb::{self as kv, Txn as _};
use tempfile::tempdir;
let location = tempdir().unwrap();
let env_builder = kv::EnvBuilder::new().dir(location.path()).max_dbs(1);
let mut env_rw = unsafe { env_builder.open_rw() }.unwrap();
let db_opts = kv::DbOptions::new()
.key_type::<str>()
.value_type::<i32>()
.name("account_balance");
let db = unsafe { env_rw.create_db(&db_opts) }.unwrap();
Implementations
sourceimpl<K: ?Sized, V: ?Sized, C> DbOptions<K, V, C, ()> where
C: Constraint,
impl<K: ?Sized, V: ?Sized, C> DbOptions<K, V, C, ()> where
C: Constraint,
sourcepub const fn keys_unique(self) -> DbOptions<K, V, KeysUnique, ()>
pub const fn keys_unique(self) -> DbOptions<K, V, KeysUnique, ()>
Clear dupsort
option (also clears reversedup
option)
See DbOptions::keys_duplicate
for setting dupsort
option and
DbOptions::has_duplicate_keys
for getting current state of flag.
sourcepub const fn keys_duplicate(self) -> DbOptions<K, V, KeysDuplicate, ()>
pub const fn keys_duplicate(self) -> DbOptions<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 DbOptions::keys_unique
for clearing dupsort
option and
DbOptions::has_duplicate_keys
for getting current state of flag.
sourceimpl<K: ?Sized, V: ?Sized, C, N> DbOptions<K, V, C, N> where
C: Constraint,
impl<K: ?Sized, V: ?Sized, C, N> DbOptions<K, V, C, N> where
C: Constraint,
sourcepub const fn get_reversekey(&self) -> bool
pub const fn get_reversekey(&self) -> bool
Get reversekey
option
sourcepub const fn reversekey(self, flag: bool) -> Self
pub const fn reversekey(self, flag: bool) -> Self
Set or clear reversekey
option
sourcepub fn unnamed(self) -> DbOptions<K, V, C, Option<CString>>
pub fn unnamed(self) -> DbOptions<K, V, C, Option<CString>>
Use unnamed database
Should be used as last builder method because some other builder methods are not available anymore after calling this method.
sourcepub fn name<T: Into<Vec<u8>>>(
self,
name: T
) -> DbOptions<K, V, C, Option<CString>>
pub fn name<T: Into<Vec<u8>>>(
self,
name: T
) -> DbOptions<K, V, C, Option<CString>>
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.
sourcepub fn strip_name<T: Into<Vec<u8>>>(self) -> DbOptions<K, V, C, ()>
pub fn strip_name<T: Into<Vec<u8>>>(self) -> DbOptions<K, V, C, ()>
Remove name information
NOTE: This does not select the unnamed database. To select the unnamed
database, use DbOptions::unnamed
.
sourceimpl<K: ?Sized, V: ?Sized, C: Constraint, N> DbOptions<K, V, C, N>
impl<K: ?Sized, V: ?Sized, C: Constraint, N> DbOptions<K, V, C, N>
sourcepub fn has_duplicate_keys(&self) -> bool
pub fn has_duplicate_keys(&self) -> bool
Returns true if duplicate keys are allowed (i.e. is dupsort
option set?)
sourceimpl<K: ?Sized, V: ?Sized, N> DbOptions<K, V, KeysDuplicate, N>
impl<K: ?Sized, V: ?Sized, N> DbOptions<K, V, KeysDuplicate, N>
sourcepub const fn get_reversedup(&self) -> bool
pub const fn get_reversedup(&self) -> bool
Get reversedup
option
sourcepub const fn reversedup(self, flag: bool) -> Self
pub const fn reversedup(self, flag: bool) -> Self
Set or clear reversedup
option
Trait Implementations
Auto Trait Implementations
impl<K: ?Sized, V: ?Sized, C, N> RefUnwindSafe for DbOptions<K, V, C, N> where
C: RefUnwindSafe,
N: RefUnwindSafe,
impl<K: ?Sized, V: ?Sized, C, N> Send for DbOptions<K, V, C, N> where
C: Send,
N: Send,
impl<K: ?Sized, V: ?Sized, C, N> Sync for DbOptions<K, V, C, N> where
C: Sync,
N: Sync,
impl<K: ?Sized, V: ?Sized, C, N> Unpin for DbOptions<K, V, C, N> where
C: Unpin,
N: Unpin,
impl<K: ?Sized, V: ?Sized, C, N> UnwindSafe for DbOptions<K, V, C, N> where
C: UnwindSafe,
N: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more