aboutsummaryrefslogtreecommitdiffstats
path: root/src/threads.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/threads.rs')
-rw-r--r--src/threads.rs40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/threads.rs b/src/threads.rs
index 20fc302..a98caba 100644
--- a/src/threads.rs
+++ b/src/threads.rs
@@ -2,38 +2,46 @@ use std::ops::Drop;
use std::iter::Iterator;
use std::marker::PhantomData;
-use utils::NewFromPtr;
+use utils::FromPtr;
use Query;
use Thread;
use ffi;
#[derive(Debug)]
-pub struct Threads<'d:'q, 'q>(
- *mut ffi::notmuch_threads_t,
- PhantomData<&'q Query<'d>>,
-);
-
-impl<'d, 'q> NewFromPtr<*mut ffi::notmuch_threads_t> for Threads<'d, 'q> {
- fn new(ptr: *mut ffi::notmuch_threads_t) -> Threads<'d, 'q> {
- Threads(ptr, PhantomData)
- }
+pub(crate) struct ThreadsPtr {
+ pub ptr: *mut ffi::notmuch_threads_t
}
-impl<'d, 'q> Drop for Threads<'d, 'q> {
+impl Drop for ThreadsPtr {
fn drop(&mut self) {
unsafe {
- ffi::notmuch_threads_destroy(self.0)
+ ffi::notmuch_threads_destroy(self.ptr)
};
}
}
+#[derive(Debug)]
+pub struct Threads<'d:'q, 'q>{
+ handle: ThreadsPtr,
+ phantom: PhantomData<&'q Query<'d>>,
+}
+
+impl<'d, 'q> FromPtr<*mut ffi::notmuch_threads_t> for Threads<'d, 'q> {
+ fn from_ptr(ptr: *mut ffi::notmuch_threads_t) -> Threads<'d, 'q> {
+ Threads{
+ handle: ThreadsPtr{ptr},
+ phantom: PhantomData
+ }
+ }
+}
+
impl<'d, 'q> Iterator for Threads<'d, 'q> {
type Item = Thread<'d, 'q>;
fn next(self: &mut Self) -> Option<Self::Item> {
let valid = unsafe {
- ffi::notmuch_threads_valid(self.0)
+ ffi::notmuch_threads_valid(self.handle.ptr)
};
if valid == 0{
@@ -41,12 +49,12 @@ impl<'d, 'q> Iterator for Threads<'d, 'q> {
}
let cthread = unsafe {
- let t = ffi::notmuch_threads_get(self.0);
- ffi::notmuch_threads_move_to_next(self.0);
+ let t = ffi::notmuch_threads_get(self.handle.ptr);
+ ffi::notmuch_threads_move_to_next(self.handle.ptr);
t
};
- Some(Self::Item::new(cthread))
+ Some(Self::Item::from_ptr(cthread))
}
}