From 4b19b951dd2fb7aa7bc662170c91401f2e8fac3b Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Fri, 14 Dec 2018 18:45:20 +0100 Subject: remove StreamingIterator again as the iterators don't actually have ownership over items --- src/thread.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/thread.rs') diff --git a/src/thread.rs b/src/thread.rs index 3b58a3e..9569cbc 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -2,37 +2,29 @@ use std::ops::Drop; use supercow::{Phantomcow, Supercow}; use crate::ffi; -use crate::utils::ToStr; +use crate::utils::{ToStr, ScopedSupercow, ScopedPhantomcow}; use crate::Messages; -use crate::MessagesOwner; +use crate::MessageOwner; use crate::Tags; use crate::TagsOwner; -pub trait ThreadOwner {} +pub trait ThreadOwner: Send + Sync {} #[derive(Debug)] pub(crate) struct ThreadPtr { pub ptr: *mut ffi::notmuch_thread_t, } -// TODO: The iterator doesn't actually own these, so dropping these will -// generate a segfault when a new iterator is constructed. -// impl Drop for ThreadPtr { -// fn drop(&mut self) { -// unsafe { ffi::notmuch_thread_destroy(self.ptr) }; -// } -// } - #[derive(Debug)] pub struct Thread<'o, O> where O: ThreadOwner, { pub(crate) handle: ThreadPtr, - marker: Phantomcow<'o, O>, + pub(crate) marker: ScopedPhantomcow<'o, O>, } -impl<'o, O> MessagesOwner for Thread<'o, O> where O: ThreadOwner + 'o {} +impl<'o, O> MessageOwner for Thread<'o, O> where O: ThreadOwner + 'o {} impl<'o, O> TagsOwner for Thread<'o, O> where O: ThreadOwner + 'o {} impl<'o, O> Thread<'o, O> @@ -41,7 +33,7 @@ where { pub fn from_ptr

(ptr: *mut ffi::notmuch_thread_t, owner: P) -> Thread<'o, O> where - P: Into>, + P: Into>, { Thread { handle: ThreadPtr { ptr }, @@ -111,23 +103,23 @@ where { fn tags<'s, S>(thread: S) -> Tags<'s, Thread<'o, O>> where - S: Into>>, + S: Into>>, { let threadref = thread.into(); Tags::from_ptr( unsafe { ffi::notmuch_thread_get_tags(threadref.handle.ptr) }, - Supercow::phantom(threadref), + ScopedSupercow::phantom(threadref), ) } fn toplevel_messages<'s, S>(thread: S) -> Messages<'s, Thread<'o, O>> where - S: Into>>, + S: Into>>, { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) }, - Supercow::phantom(threadref), + ScopedSupercow::phantom(threadref), ) } @@ -135,12 +127,12 @@ where /// oldest-first order. fn messages<'s, S>(thread: S) -> Messages<'s, Thread<'o, O>> where - S: Into>>, + S: Into>>, { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) }, - Supercow::phantom(threadref), + ScopedSupercow::phantom(threadref), ) } } -- cgit v1.2.1