Struct mmtkvdb::EnvBuilder
source · pub struct EnvBuilder<P> { /* private fields */ }
Expand description
Options for opening an environment
This struct follows the builder pattern. Start with EnvBuilder::new
and
open the environment with EnvBuilder::open_ro
(for read-only access) or
EnvBuilder::open_rw
(for read-write access).
Caveats / Safety
Do not open the same environment twice in the same process.
Since this cannot be easily ensured (and because the environment must be
free of corruption on the storage medium), open_ro
and open_rw
are marked as unsafe
.
Use EnvRo::clone
to (re-)open an already open environment in read-only
mode.
The file format is platform specific, so endianness and word size must not change across use.
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 env_ro = env_rw.clone(); // clones `EnvRo` due to deref coercion
Implementations§
source§impl<P> EnvBuilder<P>
impl<P> EnvBuilder<P>
sourcepub fn dir<'a>(self, path: &'a impl AsRef<Path> + ?Sized) -> EnvBuilder<&'a Path>
pub fn dir<'a>(self, path: &'a impl AsRef<Path> + ?Sized) -> EnvBuilder<&'a Path>
Set directory location
sourcepub fn file<'a>(
self,
path: &'a impl AsRef<Path> + ?Sized
) -> EnvBuilder<&'a Path>
pub fn file<'a>(
self,
path: &'a impl AsRef<Path> + ?Sized
) -> EnvBuilder<&'a Path>
Set file location
sourcepub const fn get_writemap(&self) -> bool
pub const fn get_writemap(&self) -> bool
Get writable memory map option
sourcepub const fn writemap(self, flag: bool) -> Self
pub const fn writemap(self, flag: bool) -> Self
Set or clear writable memory map option
Enabling the writable memory map is incompatible with nested
transactions (see TxnRw::nested
).
sourcepub const fn get_nometasync(&self) -> bool
pub const fn get_nometasync(&self) -> bool
Get no-meta-sync option
sourcepub const fn nometasync(self, flag: bool) -> Self
pub const fn nometasync(self, flag: bool) -> Self
Set or clear no-meta-sync option
sourcepub const fn get_max_size(&self) -> usize
pub const fn get_max_size(&self) -> usize
Get maximum environment size
sourcepub const fn get_max_readers(&self) -> usize
pub const fn get_max_readers(&self) -> usize
Get maximum number of concurrent readers
sourcepub const fn max_readers(self, max_readers: usize) -> Self
pub const fn max_readers(self, max_readers: usize) -> Self
Set maximum number of concurrent readers
sourcepub const fn get_max_dbs(&self) -> usize
pub const fn get_max_dbs(&self) -> usize
Get maximum number of named databases
sourcepub const fn get_unix_file_mode(&self) -> u32
pub const fn get_unix_file_mode(&self) -> u32
Get file mode
sourcepub const fn unix_file_mode(self, mode: u32) -> Self
pub const fn unix_file_mode(self, mode: u32) -> Self
Set file mode
sourcepub const fn nestable_txns(&self) -> bool
pub const fn nestable_txns(&self) -> bool
Check if transactions are nestable with current options
See TxnRw::nested
.
source§impl<'a> EnvBuilder<&'a Path>
impl<'a> EnvBuilder<&'a Path>
sourcepub unsafe fn open_ro(&self) -> Result<EnvRo>
pub unsafe fn open_ro(&self) -> Result<EnvRo>
Open environment in read-only mode
Safety
- Do not open the same environment twice in the same process.
- The environment must be free of corruption on the storage medium.
- The file format is platform specific, so endianness and word size must not change across use.
sourcepub unsafe fn open_rw(&self) -> Result<EnvRw>
pub unsafe fn open_rw(&self) -> Result<EnvRw>
Open environment in read-write mode
Safety
- Do not open the same environment twice in the same process.
- The environment must be free of corruption on the storage medium.
- The file format is platform specific, so endianness and word size must not change across use.
Trait Implementations§
source§impl<P: Clone> Clone for EnvBuilder<P>
impl<P: Clone> Clone for EnvBuilder<P>
source§fn clone(&self) -> EnvBuilder<P>
fn clone(&self) -> EnvBuilder<P>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more