From 51f063aaf2cab590a6cfe42e1da3f7bbd6423ba5 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Fri, 25 Oct 2019 09:12:59 +0200 Subject: add scopable atomic operation and configlist --- src/database.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/database.rs') diff --git a/src/database.rs b/src/database.rs index c828bb2..089976d 100644 --- a/src/database.rs +++ b/src/database.rs @@ -18,6 +18,7 @@ use TagsOwner; use Message; use MessageOwner; use IndexOpts; +use ConfigList; use utils::ScopedSupercow; @@ -218,6 +219,11 @@ impl Database { ::directory(self, path) } + pub fn get_config_list<'d>(&'d self, prefix: &str) -> Result> + { + ::get_config_list(self, prefix) + } + pub fn create_query<'d>(&'d self, query_string: &str) -> Result> { ::create_query(self, query_string) } @@ -310,6 +316,22 @@ pub trait DatabaseExt { } } + fn get_config_list<'d, D>(database: D, prefix: &str) -> Result> + where + D: Into> + { + let dbref = database.into(); + + let prefix_str = CString::new(prefix).unwrap(); + + let mut cfgs = ptr::null_mut(); + unsafe { + ffi::notmuch_database_get_config_list(dbref.ptr, prefix_str.as_ptr(), &mut cfgs) + }.as_result()?; + + Ok(ConfigList::from_ptr(cfgs, Supercow::phantom(dbref))) + } + fn find_message<'d, D>(database: D, message_id: &str) -> Result>> where D: Into> @@ -406,3 +428,29 @@ impl DatabaseExt for Database {} unsafe impl Send for Database {} unsafe impl Sync for Database {} + + +#[derive(Debug)] +pub struct AtomicOperation<'d> { + database: ScopedSupercow<'d, Database>, +} + +impl<'d> AtomicOperation<'d> { + pub fn new(db: D) -> Result + where + D: Into>, + { + let database = db.into(); + database.begin_atomic()?; + Ok(AtomicOperation{ + database + }) + } +} + +impl<'d> Drop for AtomicOperation<'d> { + fn drop(&mut self) { + let _ = self.database.end_atomic(); + } +} + -- cgit v1.2.1