Struct EnvBuilder

Source
pub struct EnvBuilder { /* private fields */ }
Expand description

Constructs environment with settigs which couldn’t be changed after opening. By default it tries to create corresponding dir if it doesn’t exist, use autocreate_dir() to override that behavior

Implementations§

Source§

impl EnvBuilder

Source

pub fn new() -> EnvBuilder

Examples found in repository?
examples/simple.rs (line 6)
5fn main() {
6    let env = EnvBuilder::new().open("test-lmdb", 0o777).unwrap();
7
8    let db_handle = env.get_default_db(DbFlags::empty()).unwrap();
9    let txn = env.new_transaction().unwrap();
10    {
11        let db = txn.bind(&db_handle); // get a database bound to this transaction
12
13        let pairs = vec![("Albert", "Einstein",),
14                         ("Joe", "Smith",),
15                         ("Jack", "Daniels")];
16
17        for &(name, surname) in pairs.iter() {
18            db.set(&surname, &name).unwrap();
19        }
20    }
21
22    // Note: `commit` is choosen to be explicit as
23    // in case of failure it is responsibility of
24    // the client to handle the error
25    match txn.commit() {
26        Err(_) => panic!("failed to commit!"),
27        Ok(_) => ()
28    }
29
30    let reader = env.get_reader().unwrap();
31    let db = reader.bind(&db_handle);
32    let name = db.get::<&str>(&"Smith").unwrap();
33    println!("It's {} Smith", name);
34}
Source

pub fn flags(self, flags: EnvCreateFlags) -> EnvBuilder

Sets environment flags

Source

pub fn max_readers(self, max_readers: usize) -> EnvBuilder

Sets max concurrent readers operating on environment

Source

pub fn max_dbs(self, max_dbs: usize) -> EnvBuilder

Set max number of databases

Source

pub fn map_size(self, map_size: u64) -> EnvBuilder

Sets max environment size, i.e. size in memory/disk of all data

Source

pub fn autocreate_dir(self, autocreate_dir: bool) -> EnvBuilder

Sets whetever lmdb-rs should try to autocreate dir with default permissions on opening (default is true)

Source

pub fn open<P: AsRef<Path>>(self, path: P, perms: u32) -> MdbResult<Environment>

Opens environment in specified path

Examples found in repository?
examples/simple.rs (line 6)
5fn main() {
6    let env = EnvBuilder::new().open("test-lmdb", 0o777).unwrap();
7
8    let db_handle = env.get_default_db(DbFlags::empty()).unwrap();
9    let txn = env.new_transaction().unwrap();
10    {
11        let db = txn.bind(&db_handle); // get a database bound to this transaction
12
13        let pairs = vec![("Albert", "Einstein",),
14                         ("Joe", "Smith",),
15                         ("Jack", "Daniels")];
16
17        for &(name, surname) in pairs.iter() {
18            db.set(&surname, &name).unwrap();
19        }
20    }
21
22    // Note: `commit` is choosen to be explicit as
23    // in case of failure it is responsibility of
24    // the client to handle the error
25    match txn.commit() {
26        Err(_) => panic!("failed to commit!"),
27        Ok(_) => ()
28    }
29
30    let reader = env.get_reader().unwrap();
31    let db = reader.bind(&db_handle);
32    let name = db.get::<&str>(&"Smith").unwrap();
33    println!("It's {} Smith", name);
34}

Trait Implementations§

Source§

impl Clone for EnvBuilder

Source§

fn clone(&self) -> EnvBuilder

Returns a duplicate 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 Debug for EnvBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for EnvBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for EnvBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where T: Clone,

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.