aboutsummaryrefslogtreecommitdiffstats
path: root/notmuch/src/config_list.rs
diff options
context:
space:
mode:
Diffstat (limited to 'notmuch/src/config_list.rs')
-rw-r--r--notmuch/src/config_list.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/notmuch/src/config_list.rs b/notmuch/src/config_list.rs
new file mode 100644
index 0000000..2c1a6a4
--- /dev/null
+++ b/notmuch/src/config_list.rs
@@ -0,0 +1,58 @@
+use std::ops::Drop;
+
+use ffi;
+use Database;
+use utils::{ToStr, ScopedPhantomcow};
+
+
+#[derive(Debug)]
+pub struct ConfigList<'d> {
+ ptr: *mut ffi::notmuch_config_list_t,
+ marker: ScopedPhantomcow<'d, Database>,
+}
+
+impl<'d> Drop for ConfigList<'d> {
+ fn drop(&mut self) {
+ unsafe { ffi::notmuch_config_list_destroy(self.ptr) };
+ }
+}
+
+impl<'d> ConfigList<'d> {
+ pub(crate) fn from_ptr<O>(ptr: *mut ffi::notmuch_config_list_t, owner: O) -> ConfigList<'d>
+ where
+ O: Into<ScopedPhantomcow<'d, Database>>,
+ {
+ ConfigList {
+ ptr,
+ marker: owner.into(),
+ }
+ }
+}
+
+
+impl<'d> Iterator for ConfigList<'d>
+{
+ type Item = (String, String);
+
+ fn next(&mut self) -> Option<Self::Item> {
+ let valid = unsafe { ffi::notmuch_config_list_valid(self.ptr) };
+
+ if valid == 0 {
+ return None;
+ }
+
+ let (k, v) = unsafe {
+ let key = ffi::notmuch_config_list_key(self.ptr);
+ let value = ffi::notmuch_config_list_value(self.ptr);
+
+ ffi::notmuch_config_list_move_to_next(self.ptr);
+
+ (key, value)
+ };
+
+ Some((k.to_string_lossy().to_string(), v.to_string_lossy().to_string()))
+ }
+}
+
+unsafe impl<'d> Send for ConfigList<'d> {}
+unsafe impl<'d> Sync for ConfigList<'d> {}