diff options
Diffstat (limited to 'src/database.rs')
| -rw-r--r-- | src/database.rs | 86 |
1 files changed, 56 insertions, 30 deletions
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<P: AsRef<Path>>(path: &P) -> Result<Self> { + pub fn create<P>(path: &P) -> Result<Self> + where + P: AsRef<Path>, + { 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<P: AsRef<Path>>(path: &P, mode: DatabaseMode) -> Result<Self> { + pub fn open<P>(path: &P, mode: DatabaseMode) -> Result<Self> + where + P: AsRef<Path>, + { 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<P: AsRef<Path>, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - ) -> Result<()> { + pub fn compact<P, F>(path: &P, backup_path: Option<&P>) -> Result<()> + where + P: AsRef<Path>, + F: FnMut(&str), + { let status: Option<F> = None; Database::_compact(path, backup_path, status) } - pub fn compact_with_status<P: AsRef<Path>, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - status: F, - ) -> Result<()> { + pub fn compact_with_status<P, F>(path: &P, backup_path: Option<&P>, status: F) -> Result<()> + where + P: AsRef<Path>, + F: FnMut(&str), + { Database::_compact(path, backup_path, Some(status)) } - fn _compact<P: AsRef<Path>, F: FnMut(&str)>( - path: &P, - backup_path: Option<&P>, - status: Option<F>, - ) -> Result<()> { + fn _compact<P, F>(path: &P, backup_path: Option<&P>, status: Option<F>) -> Result<()> + where + P: AsRef<Path>, + F: FnMut(&str), + { extern "C" fn wrapper<F: FnMut(&str)>( 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<F: FnMut(f64)>(&mut self) -> Result<()> { + pub fn upgrade<F>(&mut self) -> Result<()> + where + F: FnMut(f64), + { let status: Option<F> = None; self._upgrade(status) } - pub fn upgrade_with_status<F: FnMut(f64)>(&mut self, status: F) -> Result<()> { + pub fn upgrade_with_status<F>(&mut self, status: F) -> Result<()> + where + F: FnMut(f64), + { self._upgrade(Some(status)) } - fn _upgrade<F: FnMut(f64)>(&mut self, status: Option<F>) -> Result<()> { + fn _upgrade<F>(&mut self, status: Option<F>) -> Result<()> + where + F: FnMut(f64), + { #[allow(trivial_numeric_casts)] - extern "C" fn wrapper<F: FnMut(f64)>(closure: *mut libc::c_void, progress: libc::c_double) { + extern "C" fn wrapper<F>(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<Path>>(&'d self, path: &P) -> Result<Option<Directory<'d>>> { + pub fn directory<'d, P>(&'d self, path: &P) -> Result<Option<Directory<'d>>> + where + P: AsRef<Path>, + { <Self as DatabaseExt>::directory(self, path) } @@ -222,10 +244,10 @@ impl Database { } pub trait DatabaseExt { - fn create_query<'d, D: Into<Supercow<'d, Database>>>( - database: D, - query_string: &str, - ) -> Result<Query<'d>> { + fn create_query<'d, D>(database: D, query_string: &str) -> Result<Query<'d>> + where + D: Into<Supercow<'d, Database>>, + { 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<Supercow<'d, Database>>>(database: D) -> Result<Tags<'d, Database>> { + fn all_tags<'d, D>(database: D) -> Result<Tags<'d, Database>> + where + D: Into<Supercow<'d, Database>>, + { 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<Supercow<'d, Database>>, P: AsRef<Path>>( - database: D, - path: &P, - ) -> Result<Option<Directory<'d>>> { + fn directory<'d, D, P>(database: D, path: &P) -> Result<Option<Directory<'d>>> + where + D: Into<Supercow<'d, Database>>, + P: AsRef<Path>, + { let dbref = database.into(); let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); |
