diff options
| author | C. Morgan Hamill <me@cmhamill.org> | 2015-03-20 18:56:28 +0100 |
|---|---|---|
| committer | C. Morgan Hamill <me@cmhamill.org> | 2015-03-20 18:56:28 +0100 |
| commit | 99e3507507e114fb4d1d27de6a7dcf1f8caaa73d (patch) | |
| tree | d9a0930c45687b4cfa4b9cbd93ac9fe0954b2e3e /src | |
| parent | 3deae99643336c653bb3ed8926ba3ac300e340ed (diff) | |
| download | mail-99e3507507e114fb4d1d27de6a7dcf1f8caaa73d.tar.gz | |
Add `Database::upgrade()` and related methods.
Not so simple wrapper around notmuch API's `notmuch_database_upgrade()`
function. Variants with and without a callback parameter are provided.
Diffstat (limited to 'src')
| -rw-r--r-- | src/database.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/database.rs b/src/database.rs index b3812eb..20c2a24 100644 --- a/src/database.rs +++ b/src/database.rs @@ -117,6 +117,39 @@ impl Database { ffi::notmuch_database_needs_upgrade(self.0) == 1 } } + + pub fn upgrade<F: FnMut(f64)>(&self) -> Result<()> { + let status: Option<F> = None; + self._upgrade(status) + } + + pub fn upgrade_with_status<F: FnMut(f64)>(&self, status: F) -> Result<()> { + self._upgrade(Some(status)) + } + + fn _upgrade<F: FnMut(f64)>(&self, status: Option<F>) -> Result<()> { + + extern fn wrapper<F: FnMut(f64)>( + closure: *mut libc::c_void, progress: libc::c_double, + ) { + let closure = closure as *mut F; + unsafe { + (*closure)(progress as f64) + } + } + + try!(unsafe { + ffi::notmuch_database_upgrade( + self.0, + 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(()) + } } impl ops::Drop for Database { |
