diff options
| author | eaon <eaon@mit.edu> | 2018-11-21 17:30:36 +0100 |
|---|---|---|
| committer | eaon <eaon@mit.edu> | 2018-11-21 17:32:57 +0100 |
| commit | bed2b54ea403872b7e540ade251e9609090a7cf5 (patch) | |
| tree | 23c29189c754d8a61154d231f076bbc6ce5c2153 | |
| parent | 678010129d42a1647458a6919a0e17148e7bc506 (diff) | |
| download | mail-bed2b54ea403872b7e540ade251e9609090a7cf5.tar.gz | |
Use the ? operator instead of the try! macro
| -rw-r--r-- | src/database.rs | 70 | ||||
| -rw-r--r-- | src/query.rs | 16 |
2 files changed, 37 insertions, 49 deletions
diff --git a/src/database.rs b/src/database.rs index 82579f3..5ed9537 100644 --- a/src/database.rs +++ b/src/database.rs @@ -65,7 +65,7 @@ impl Database { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); - try!(unsafe { ffi::notmuch_database_create(path_str.as_ptr(), &mut db) }.as_result()); + unsafe { ffi::notmuch_database_create(path_str.as_ptr(), &mut db) }.as_result()?; Ok(Database { handle: DatabasePtr { ptr: db }, @@ -79,10 +79,8 @@ impl Database { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); - try!( - unsafe { ffi::notmuch_database_open(path_str.as_ptr(), mode.into(), &mut db,) } - .as_result() - ); + unsafe { ffi::notmuch_database_open(path_str.as_ptr(), mode.into(), &mut db) } + .as_result()?; Ok(Database { handle: DatabasePtr { ptr: db }, @@ -90,7 +88,7 @@ impl Database { } pub fn close(&mut self) -> Result<()> { - try!(unsafe { ffi::notmuch_database_close(self.handle.ptr) }.as_result()); + unsafe { ffi::notmuch_database_close(self.handle.ptr) }.as_result()?; Ok(()) } @@ -129,20 +127,18 @@ impl Database { let backup_path = backup_path.map(|p| CString::new(p.as_ref().to_str().unwrap()).unwrap()); - try!( - unsafe { - ffi::notmuch_database_compact( - path_str.as_ptr(), - backup_path.map_or(ptr::null(), |p| p.as_ptr()), - if status.is_some() { - Some(wrapper::<F>) - } else { - None - }, - status.map_or(ptr::null_mut(), |f| &f as *const _ as *mut libc::c_void), - ) - }.as_result() - ); + unsafe { + ffi::notmuch_database_compact( + path_str.as_ptr(), + backup_path.map_or(ptr::null(), |p| p.as_ptr()), + if status.is_some() { + Some(wrapper::<F>) + } else { + None + }, + status.map_or(ptr::null_mut(), |f| &f as *const _ as *mut libc::c_void), + ) + }.as_result()?; Ok(()) } @@ -209,19 +205,17 @@ impl Database { unsafe { (*closure)(progress as f64) } } - try!( - unsafe { - ffi::notmuch_database_upgrade( - self.handle.ptr, - if status.is_some() { - Some(wrapper::<F>) - } else { - None - }, - status.map_or(ptr::null_mut(), |f| &f as *const _ as *mut libc::c_void), - ) - }.as_result() - ); + unsafe { + ffi::notmuch_database_upgrade( + self.handle.ptr, + if status.is_some() { + Some(wrapper::<F>) + } else { + None + }, + status.map_or(ptr::null_mut(), |f| &f as *const _ as *mut libc::c_void), + ) + }.as_result()?; Ok(()) } @@ -283,11 +277,9 @@ pub trait DatabaseExt { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut dir = ptr::null_mut(); - try!( - unsafe { - ffi::notmuch_database_get_directory(dbref.handle.ptr, path_str.as_ptr(), &mut dir) - }.as_result() - ); + unsafe { + ffi::notmuch_database_get_directory(dbref.handle.ptr, path_str.as_ptr(), &mut dir) + }.as_result()?; if dir.is_null() { Ok(None) @@ -310,7 +302,7 @@ pub trait DatabaseExt { ffi::notmuch_database_remove_message(dbref.handle.ptr, msg_path.as_ptr()) }) } - None => Status::FileError + None => Status::FileError, } } } diff --git a/src/query.rs b/src/query.rs index c73d4ca..38711e9 100644 --- a/src/query.rs +++ b/src/query.rs @@ -82,7 +82,7 @@ impl<'d> Query<'d> { pub fn count_messages(self: &Self) -> Result<u32> { let mut cnt = 0; - try!(unsafe { ffi::notmuch_query_count_messages(self.handle.ptr, &mut cnt,) }.as_result()); + unsafe { ffi::notmuch_query_count_messages(self.handle.ptr, &mut cnt) }.as_result()?; Ok(cnt) } @@ -93,7 +93,7 @@ impl<'d> Query<'d> { pub fn count_threads(self: &Self) -> Result<u32> { let mut cnt = 0; - try!(unsafe { ffi::notmuch_query_count_threads(self.handle.ptr, &mut cnt,) }.as_result()); + unsafe { ffi::notmuch_query_count_threads(self.handle.ptr, &mut cnt) }.as_result()?; Ok(cnt) } @@ -107,10 +107,8 @@ pub trait QueryExt<'d> { let queryref = query.into(); let mut thrds = ptr::null_mut(); - try!( - unsafe { ffi::notmuch_query_search_threads(queryref.handle.ptr, &mut thrds) } - .as_result() - ); + unsafe { ffi::notmuch_query_search_threads(queryref.handle.ptr, &mut thrds) } + .as_result()?; Ok(Threads::from_ptr(thrds, Supercow::phantom(queryref))) } @@ -122,10 +120,8 @@ pub trait QueryExt<'d> { let queryref = query.into(); let mut msgs = ptr::null_mut(); - try!( - unsafe { ffi::notmuch_query_search_messages(queryref.handle.ptr, &mut msgs) } - .as_result() - ); + unsafe { ffi::notmuch_query_search_messages(queryref.handle.ptr, &mut msgs) } + .as_result()?; Ok(Messages::from_ptr(msgs, Supercow::phantom(queryref))) } |
