diff --git a/src/cursor.rs b/src/cursor.rs index 88aa8cf..2395116 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -28,7 +28,7 @@ pub trait Cursor<'txn> { let mut key_val = slice_to_val(key); let mut data_val = slice_to_val(data); let key_ptr = key_val.mv_data; - try!(lmdb_result(ffi::mdb_cursor_get(self.cursor(), &mut key_val, &mut data_val, op))); + lmdb_result(ffi::mdb_cursor_get(self.cursor(), &mut key_val, &mut data_val, op))?; let key_out = if key_ptr != key_val.mv_data { Some(val_to_slice(key_val)) } else { None }; let data_out = val_to_slice(data_val); Ok((key_out, data_out)) @@ -91,7 +91,7 @@ pub trait Cursor<'txn> { /// key. fn iter_dup_of(&mut self, key: &K) -> Result> where K: AsRef<[u8]> { - try!(self.get(Some(key.as_ref()), None, ffi::MDB_SET)); + self.get(Some(key.as_ref()), None, ffi::MDB_SET)?; Ok(Iter::new(self.cursor(), ffi::MDB_GET_CURRENT, ffi::MDB_NEXT_DUP)) } } @@ -127,7 +127,7 @@ impl <'txn> RoCursor<'txn> { #[doc(hidden)] pub fn new(txn: &'txn T, db: Database) -> Result> where T: Transaction { let mut cursor: *mut ffi::MDB_cursor = ptr::null_mut(); - unsafe { try!(lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))); } + unsafe { lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))?; } Ok(RoCursor { cursor: cursor, _marker: PhantomData, @@ -166,7 +166,7 @@ impl <'txn> RwCursor<'txn> { #[doc(hidden)] pub fn new(txn: &'txn T, db: Database) -> Result> where T: Transaction { let mut cursor: *mut ffi::MDB_cursor = ptr::null_mut(); - unsafe { try!(lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))); } + unsafe { lmdb_result(ffi::mdb_cursor_open(txn.txn(), db.dbi(), &mut cursor))?; } Ok(RwCursor { cursor: cursor, _marker: PhantomData }) } diff --git a/src/database.rs b/src/database.rs index 8a92ad1..71ed4ca 100644 --- a/src/database.rs +++ b/src/database.rs @@ -28,7 +28,7 @@ impl Database { let c_name = name.map(|n| CString::new(n).unwrap()); let name_ptr = if let Some(ref c_name) = c_name { c_name.as_ptr() } else { ptr::null() }; let mut dbi: ffi::MDB_dbi = 0; - try!(lmdb_result(ffi::mdb_dbi_open(txn, name_ptr, flags, &mut dbi))); + lmdb_result(ffi::mdb_dbi_open(txn, name_ptr, flags, &mut dbi))?; Ok(Database { dbi: dbi }) } diff --git a/src/environment.rs b/src/environment.rs index 26bcbdd..c664e3a 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -76,9 +76,9 @@ impl Environment { /// The database name may not contain the null character. pub fn open_db<'env>(&'env self, name: Option<&str>) -> Result { let mutex = self.dbi_open_mutex.lock(); - let txn = try!(self.begin_ro_txn()); - let db = unsafe { try!(txn.open_db(name)) }; - try!(txn.commit()); + let txn = self.begin_ro_txn()?; + let db = unsafe { txn.open_db(name)? }; + txn.commit()?; drop(mutex); Ok(db) } @@ -102,18 +102,18 @@ impl Environment { flags: DatabaseFlags) -> Result { let mutex = self.dbi_open_mutex.lock(); - let txn = try!(self.begin_rw_txn()); - let db = unsafe { try!(txn.create_db(name, flags)) }; - try!(txn.commit()); + let txn = self.begin_rw_txn()?; + let db = unsafe { txn.create_db(name, flags)? }; + txn.commit()?; drop(mutex); Ok(db) } pub fn get_db_flags<'env>(&'env self, db: Database) -> Result { - let txn = try!(self.begin_ro_txn()); + let txn = self.begin_ro_txn()?; let mut flags: c_uint = 0; unsafe { - try!(lmdb_result(ffi::mdb_dbi_flags(txn.txn(), db.dbi(), &mut flags))); + lmdb_result(ffi::mdb_dbi_flags(txn.txn(), db.dbi(), &mut flags))?; } Ok(DatabaseFlags::from_bits(flags).unwrap()) } diff --git a/src/transaction.rs b/src/transaction.rs index b5278d8..1d9e49f 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -98,7 +98,7 @@ pub trait Transaction : Sized { fn db_flags(&self, db: Database) -> Result { let mut flags: c_uint = 0; unsafe { - try!(lmdb_result(ffi::mdb_dbi_flags(self.txn(), db.dbi(), &mut flags))); + lmdb_result(ffi::mdb_dbi_flags(self.txn(), db.dbi(), &mut flags))?; } Ok(DatabaseFlags::from_bits_truncate(flags)) } @@ -130,10 +130,7 @@ impl <'env> RoTransaction<'env> { pub fn new(env: &'env Environment) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); unsafe { - try!(lmdb_result(ffi::mdb_txn_begin(env.env(), - ptr::null_mut(), - ffi::MDB_RDONLY, - &mut txn))); + lmdb_result(ffi::mdb_txn_begin(env.env(), ptr::null_mut(), ffi::MDB_RDONLY, &mut txn))?; Ok(RoTransaction { txn: txn, _marker: PhantomData }) } } @@ -195,7 +192,7 @@ impl <'env> InactiveTransaction<'env> { let txn = self.txn; unsafe { mem::forget(self); - try!(lmdb_result(ffi::mdb_txn_renew(txn))) + lmdb_result(ffi::mdb_txn_renew(txn))? }; Ok(RoTransaction { txn: txn, _marker: PhantomData }) } @@ -227,10 +224,10 @@ impl <'env> RwTransaction<'env> { pub fn new(env: &'env Environment) -> Result> { let mut txn: *mut ffi::MDB_txn = ptr::null_mut(); unsafe { - try!(lmdb_result(ffi::mdb_txn_begin(env.env(), - ptr::null_mut(), - EnvironmentFlags::empty().bits(), - &mut txn))); + lmdb_result(ffi::mdb_txn_begin(env.env(), + ptr::null_mut(), + EnvironmentFlags::empty().bits(), + &mut txn))?; Ok(RwTransaction { txn: txn, _marker: PhantomData }) } } @@ -305,11 +302,11 @@ impl <'env> RwTransaction<'env> { let mut data_val: ffi::MDB_val = ffi::MDB_val { mv_size: len, mv_data: ptr::null_mut::() }; unsafe { - try!(lmdb_result(ffi::mdb_put(self.txn(), - database.dbi(), - &mut key_val, - &mut data_val, - flags.bits() | ffi::MDB_RESERVE))); + lmdb_result(ffi::mdb_put(self.txn(), + database.dbi(), + &mut key_val, + &mut data_val, + flags.bits() | ffi::MDB_RESERVE))?; Ok(slice::from_raw_parts_mut(data_val.mv_data as *mut u8, data_val.mv_size as usize)) }