aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread.rs')
-rw-r--r--src/thread.rs71
1 files changed, 40 insertions, 31 deletions
diff --git a/src/thread.rs b/src/thread.rs
index 4f98c26..60782f5 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -2,7 +2,7 @@ use std::ops::Drop;
use std::marker::PhantomData;
use ffi;
use utils::{
- NewFromPtr,
+ FromPtr,
ToStr
};
use Query;
@@ -10,14 +10,31 @@ use Messages;
use Tags;
#[derive(Debug)]
-pub struct Thread<'d:'q, 'q>(
- pub(crate) *mut ffi::notmuch_thread_t,
- PhantomData<&'q Query<'d>>,
-);
-
-impl<'d, 'q> NewFromPtr<*mut ffi::notmuch_thread_t> for Thread<'d, 'q> {
- fn new(ptr: *mut ffi::notmuch_thread_t) -> Thread<'d, 'q> {
- Thread(ptr, PhantomData)
+pub(crate) struct ThreadPtr {
+ pub ptr: *mut ffi::notmuch_thread_t
+}
+
+impl Drop for ThreadPtr {
+ fn drop(&mut self) {
+ unsafe {
+ ffi::notmuch_thread_destroy(self.ptr)
+ };
+ }
+}
+
+
+#[derive(Debug)]
+pub struct Thread<'d:'q, 'q>{
+ pub(crate) handle: ThreadPtr,
+ phantom: PhantomData<&'q Query<'d>>,
+}
+
+impl<'d, 'q> FromPtr<*mut ffi::notmuch_thread_t> for Thread<'d, 'q> {
+ fn from_ptr(ptr: *mut ffi::notmuch_thread_t) -> Thread<'d, 'q> {
+ Thread{
+ handle: ThreadPtr{ptr},
+ phantom: PhantomData
+ }
}
}
@@ -25,7 +42,7 @@ impl<'d, 'q> Thread<'d, 'q>{
pub fn id(self: &Self) -> String{
let tid = unsafe {
- ffi::notmuch_thread_get_thread_id(self.0)
+ ffi::notmuch_thread_get_thread_id(self.handle.ptr)
};
tid.to_str().unwrap().to_string()
}
@@ -33,42 +50,42 @@ impl<'d, 'q> Thread<'d, 'q>{
pub fn total_messages(self: &Self) -> i32{
unsafe {
- ffi::notmuch_thread_get_total_messages(self.0)
+ ffi::notmuch_thread_get_total_messages(self.handle.ptr)
}
}
#[cfg(feature = "0.26")]
pub fn total_files(self: &Self) -> i32{
unsafe {
- ffi::notmuch_thread_get_total_files(self.0)
+ ffi::notmuch_thread_get_total_files(self.handle.ptr)
}
}
pub fn toplevel_messages(self: &Self) -> Messages{
- Messages::new(unsafe {
- ffi::notmuch_thread_get_toplevel_messages(self.0)
+ Messages::from_ptr(unsafe {
+ ffi::notmuch_thread_get_toplevel_messages(self.handle.ptr)
})
}
/// Get a `Messages` iterator for all messages in 'thread' in
/// oldest-first order.
pub fn messages(self: &Self) -> Messages{
- Messages::new(unsafe {
- ffi::notmuch_thread_get_messages(self.0)
+ Messages::from_ptr(unsafe {
+ ffi::notmuch_thread_get_messages(self.handle.ptr)
})
}
- pub fn tags(self: &Self) -> Tags{
- Tags::new(unsafe {
- ffi::notmuch_thread_get_tags(self.0)
+ pub fn tags<'t>(self: &Self) -> Tags{
+ Tags::from_ptr(unsafe {
+ ffi::notmuch_thread_get_tags(self.handle.ptr)
})
}
pub fn subject(self: &Self) -> String{
let sub = unsafe {
- ffi::notmuch_thread_get_subject(self.0)
+ ffi::notmuch_thread_get_subject(self.handle.ptr)
};
sub.to_str().unwrap().to_string()
@@ -76,7 +93,7 @@ impl<'d, 'q> Thread<'d, 'q>{
pub fn authors(self: &Self) -> Vec<String>{
let athrs = unsafe {
- ffi::notmuch_thread_get_authors(self.0)
+ ffi::notmuch_thread_get_authors(self.handle.ptr)
};
athrs.to_str().unwrap().split(',').map(|s| s.to_string()).collect()
@@ -85,26 +102,18 @@ impl<'d, 'q> Thread<'d, 'q>{
/// Get the date of the oldest message in 'thread' as a time_t value.
pub fn oldest_date(self: &Self) -> i64 {
unsafe {
- ffi::notmuch_thread_get_oldest_date(self.0)
+ ffi::notmuch_thread_get_oldest_date(self.handle.ptr)
}
}
/// Get the date of the newest message in 'thread' as a time_t value.
pub fn newest_date(self: &Self) -> i64 {
unsafe {
- ffi::notmuch_thread_get_newest_date(self.0)
+ ffi::notmuch_thread_get_newest_date(self.handle.ptr)
}
}
}
-impl<'d, 'q> Drop for Thread<'d, 'q> {
- fn drop(&mut self) {
- unsafe {
- ffi::notmuch_thread_destroy(self.0)
- };
- }
-}
-
unsafe impl<'d, 'q> Send for Thread<'d, 'q> {}
unsafe impl<'d, 'q> Sync for Thread<'d, 'q> {}