Struct Transaction

Source
pub struct Transaction<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Transaction<'a>

Source

pub fn new_child(&self) -> MdbResult<Transaction<'_>>

Source

pub fn new_ro_child(&self) -> MdbResult<ReadonlyTransaction<'_>>

Source

pub fn commit(self) -> MdbResult<()>

Commits transaction, moves it out

Examples found in repository?
examples/simple.rs (line 25)
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 abort(self)

Aborts transaction, moves it out

Source

pub fn bind(&self, db_handle: &DbHandle) -> Database<'_>

Examples found in repository?
examples/simple.rs (line 11)
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<'a> Debug for Transaction<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Transaction<'a>

§

impl<'a> RefUnwindSafe for Transaction<'a>

§

impl<'a> !Send for Transaction<'a>

§

impl<'a> !Sync for Transaction<'a>

§

impl<'a> Unpin for Transaction<'a>

§

impl<'a> UnwindSafe for Transaction<'a>

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