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§

Default options for database

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.

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.

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 DbBuilder::unnamed.

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

See DbBuilder::keys_unique and DbBuilder::keys_duplicate.

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