pub struct DbOptions<K: ?Sized, V: ?Sized, C, N> { /* private fields */ }
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 Env::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 Env::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 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 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, Env as _, 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

Default options for database

Clear dupsort option (also clears reversedup option)

Set dupsort option

Set stored key type

Set stored value type

Get reversekey option

Set or clear reversekey option

Use unnamed database

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

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.

Remove name information

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

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

Get reversedup option

Set or clear reversedup option

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.