From bb8a60ddc9fdecc6c1004639514b538578e37532 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Thu, 20 Dec 2018 08:21:03 +0100 Subject: remove ptr indirection --- src/thread.rs | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'src/thread.rs') diff --git a/src/thread.rs b/src/thread.rs index 137c936..9634a57 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -8,26 +8,24 @@ use Tags; use TagsOwner; use Query; -#[derive(Debug)] -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> where 'd: 'q { - pub(crate) handle: ThreadPtr, + pub(crate) ptr: *mut ffi::notmuch_thread_t, pub(crate) marker: ScopedPhantomcow<'q, Query<'d>>, } +impl<'d, 'q> Drop for Thread<'d, 'q> +where + 'd: 'q +{ + fn drop(&mut self) { + unsafe { ffi::notmuch_thread_destroy(self.ptr) }; + } +} + impl<'d, 'q> MessageOwner for Thread<'d, 'q> where 'd: 'q {} impl<'d, 'q> TagsOwner for Thread<'d, 'q> where 'd: 'q {} @@ -40,23 +38,23 @@ where P: Into>>, { Thread { - handle: ThreadPtr { ptr }, + ptr, marker: owner.into(), } } pub fn id(self: &Self) -> String { - let tid = unsafe { ffi::notmuch_thread_get_thread_id(self.handle.ptr) }; + let tid = unsafe { ffi::notmuch_thread_get_thread_id(self.ptr) }; tid.to_str().unwrap().to_string() } pub fn total_messages(self: &Self) -> i32 { - unsafe { ffi::notmuch_thread_get_total_messages(self.handle.ptr) } + unsafe { ffi::notmuch_thread_get_total_messages(self.ptr) } } #[cfg(feature = "0.26")] pub fn total_files(self: &Self) -> i32 { - unsafe { ffi::notmuch_thread_get_total_files(self.handle.ptr) } + unsafe { ffi::notmuch_thread_get_total_files(self.ptr) } } pub fn toplevel_messages(self: &Self) -> Messages<'_, Self> { @@ -74,13 +72,13 @@ where } pub fn subject(self: &Self) -> String { - let sub = unsafe { ffi::notmuch_thread_get_subject(self.handle.ptr) }; + let sub = unsafe { ffi::notmuch_thread_get_subject(self.ptr) }; sub.to_str().unwrap().to_string() } pub fn authors(self: &Self) -> Vec { - let athrs = unsafe { ffi::notmuch_thread_get_authors(self.handle.ptr) }; + let athrs = unsafe { ffi::notmuch_thread_get_authors(self.ptr) }; athrs .to_str() @@ -92,12 +90,12 @@ where /// 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.handle.ptr) as i64 } + unsafe { ffi::notmuch_thread_get_oldest_date(self.ptr) as i64 } } /// 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.handle.ptr) as i64 } + unsafe { ffi::notmuch_thread_get_newest_date(self.ptr) as i64 } } } @@ -111,7 +109,7 @@ where { let threadref = thread.into(); Tags::from_ptr( - unsafe { ffi::notmuch_thread_get_tags(threadref.handle.ptr) }, + unsafe { ffi::notmuch_thread_get_tags(threadref.ptr) }, ScopedSupercow::phantom(threadref), ) } @@ -122,7 +120,7 @@ where { let threadref = thread.into(); Messages::from_ptr( - unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) }, + unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.ptr) }, ScopedSupercow::phantom(threadref), ) } @@ -135,7 +133,7 @@ where { let threadref = thread.into(); Messages::from_ptr( - unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) }, + unsafe { ffi::notmuch_thread_get_messages(threadref.ptr) }, ScopedSupercow::phantom(threadref), ) } -- cgit v1.2.1