From ba03b994b3318c84923f4a9a23cfc4270a5ace75 Mon Sep 17 00:00:00 2001 From: eaon Date: Mon, 12 Nov 2018 07:58:50 -0500 Subject: Switch to `where` syntax --- src/database.rs | 86 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 30 deletions(-) (limited to 'src/database.rs') diff --git a/src/database.rs b/src/database.rs index c5cb917..d5e6700 100644 --- a/src/database.rs +++ b/src/database.rs @@ -57,7 +57,10 @@ pub struct Database { impl TagsOwner for Database {} impl Database { - pub fn create>(path: &P) -> Result { + pub fn create

(path: &P) -> Result + where + P: AsRef, + { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); @@ -68,7 +71,10 @@ impl Database { }) } - pub fn open>(path: &P, mode: DatabaseMode) -> Result { + pub fn open

(path: &P, mode: DatabaseMode) -> Result + where + P: AsRef, + { let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); let mut db = ptr::null_mut(); @@ -88,27 +94,28 @@ impl Database { Ok(()) } - pub fn compact, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - ) -> Result<()> { + pub fn compact(path: &P, backup_path: Option<&P>) -> Result<()> + where + P: AsRef, + F: FnMut(&str), + { let status: Option = None; Database::_compact(path, backup_path, status) } - pub fn compact_with_status, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - status: F, - ) -> Result<()> { + pub fn compact_with_status(path: &P, backup_path: Option<&P>, status: F) -> Result<()> + where + P: AsRef, + F: FnMut(&str), + { Database::_compact(path, backup_path, Some(status)) } - fn _compact, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - status: Option, - ) -> Result<()> { + fn _compact(path: &P, backup_path: Option<&P>, status: Option) -> Result<()> + where + P: AsRef, + F: FnMut(&str), + { extern "C" fn wrapper( message: *const libc::c_char, closure: *mut libc::c_void, @@ -174,18 +181,30 @@ impl Database { unsafe { ffi::notmuch_database_needs_upgrade(self.handle.ptr) == 1 } } - pub fn upgrade(&mut self) -> Result<()> { + pub fn upgrade(&mut self) -> Result<()> + where + F: FnMut(f64), + { let status: Option = None; self._upgrade(status) } - pub fn upgrade_with_status(&mut self, status: F) -> Result<()> { + pub fn upgrade_with_status(&mut self, status: F) -> Result<()> + where + F: FnMut(f64), + { self._upgrade(Some(status)) } - fn _upgrade(&mut self, status: Option) -> Result<()> { + fn _upgrade(&mut self, status: Option) -> Result<()> + where + F: FnMut(f64), + { #[allow(trivial_numeric_casts)] - extern "C" fn wrapper(closure: *mut libc::c_void, progress: libc::c_double) { + extern "C" fn wrapper(closure: *mut libc::c_void, progress: libc::c_double) + where + F: FnMut(f64), + { let closure = closure as *mut F; unsafe { (*closure)(progress as f64) } } @@ -208,7 +227,10 @@ impl Database { Ok(()) } - pub fn directory<'d, P: AsRef>(&'d self, path: &P) -> Result>> { + pub fn directory<'d, P>(&'d self, path: &P) -> Result>> + where + P: AsRef, + { ::directory(self, path) } @@ -222,10 +244,10 @@ impl Database { } pub trait DatabaseExt { - fn create_query<'d, D: Into>>( - database: D, - query_string: &str, - ) -> Result> { + fn create_query<'d, D>(database: D, query_string: &str) -> Result> + where + D: Into>, + { let dbref = database.into(); let query_str = CString::new(query_string).unwrap(); @@ -234,7 +256,10 @@ pub trait DatabaseExt { Ok(Query::from_ptr(query, Supercow::phantom(dbref))) } - fn all_tags<'d, D: Into>>(database: D) -> Result> { + fn all_tags<'d, D>(database: D) -> Result> + where + D: Into>, + { let dbref = database.into(); let tags = unsafe { ffi::notmuch_database_get_all_tags(dbref.handle.ptr) }; @@ -242,10 +267,11 @@ pub trait DatabaseExt { Ok(Tags::from_ptr(tags, Supercow::phantom(dbref))) } - fn directory<'d, D: Into>, P: AsRef>( - database: D, - path: &P, - ) -> Result>> { + fn directory<'d, D, P>(database: D, path: &P) -> Result>> + where + D: Into>, + P: AsRef, + { let dbref = database.into(); let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); -- cgit v1.2.1