diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-12-14 18:45:20 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-12-14 18:45:20 +0100 |
| commit | 4b19b951dd2fb7aa7bc662170c91401f2e8fac3b (patch) | |
| tree | 5b436865f4ae78a90129147e1a0fd8b53b2746b2 | |
| parent | 022fb6eebf7774b19a1e1b3c6cee7bd7e1b75cd9 (diff) | |
| download | mail-4b19b951dd2fb7aa7bc662170c91401f2e8fac3b.tar.gz | |
remove StreamingIterator again as the iterators don't actually have ownership over items
| -rw-r--r-- | src/database.rs | 7 | ||||
| -rw-r--r-- | src/directory.rs | 7 | ||||
| -rw-r--r-- | src/filenames.rs | 5 | ||||
| -rw-r--r-- | src/lib.rs | 5 | ||||
| -rw-r--r-- | src/message.rs | 28 | ||||
| -rw-r--r-- | src/messages.rs | 65 | ||||
| -rw-r--r-- | src/query.rs | 17 | ||||
| -rw-r--r-- | src/tags.rs | 5 | ||||
| -rw-r--r-- | src/thread.rs | 32 | ||||
| -rw-r--r-- | src/threads.rs | 68 | ||||
| -rw-r--r-- | src/utils.rs | 30 | ||||
| -rw-r--r-- | tests/main.rs | 5 |
12 files changed, 104 insertions, 170 deletions
diff --git a/src/database.rs b/src/database.rs index fe9a39b..0ff443a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -16,6 +16,7 @@ use crate::Directory; use crate::Query; use crate::Tags; use crate::TagsOwner; +use crate::utils::{ScopedSupercow, ScopedPhantomcow}; // Re-exported under database module for pretty namespacin'. pub use crate::ffi::DatabaseMode; @@ -258,18 +259,18 @@ pub trait DatabaseExt { fn all_tags<'d, D>(database: D) -> Result<Tags<'d, Database>> where - D: Into<Supercow<'d, Database>>, + D: Into<ScopedSupercow<'d, Database>>, { let dbref = database.into(); let tags = unsafe { ffi::notmuch_database_get_all_tags(dbref.handle.ptr) }; - Ok(Tags::from_ptr(tags, Supercow::phantom(dbref))) + Ok(Tags::from_ptr(tags, ScopedSupercow::phantom(dbref))) } fn directory<'d, D, P>(database: D, path: &P) -> Result<Option<Directory<'d>>> where - D: Into<Supercow<'d, Database>>, + D: Into<ScopedSupercow<'d, Database>>, P: AsRef<Path>, { let dbref = database.into(); diff --git a/src/directory.rs b/src/directory.rs index be2ea5c..09baf77 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -5,6 +5,7 @@ use crate::ffi; use crate::Database; use crate::Filenames; use crate::FilenamesOwner; +use crate::utils::{ScopedSupercow, ScopedPhantomcow}; #[derive(Debug)] pub(crate) struct DirectoryPtr { @@ -20,7 +21,7 @@ impl Drop for DirectoryPtr { #[derive(Debug)] pub struct Directory<'d> { handle: DirectoryPtr, - marker: Phantomcow<'d, Database>, + marker: ScopedPhantomcow<'d, Database>, } impl<'d> FilenamesOwner for Directory<'d> {} @@ -28,7 +29,7 @@ impl<'d> FilenamesOwner for Directory<'d> {} impl<'d> Directory<'d> { pub fn from_ptr<O>(ptr: *mut ffi::notmuch_directory_t, owner: O) -> Directory<'d> where - O: Into<Phantomcow<'d, Database>>, + O: Into<ScopedPhantomcow<'d, Database>>, { Directory { handle: DirectoryPtr { ptr }, @@ -44,7 +45,7 @@ impl<'d> Directory<'d> { pub trait DirectoryExt<'d> { fn child_directories<'s, S>(directory: S) -> Filenames<'s, Directory<'d>> where - S: Into<Supercow<'s, Directory<'d>>>, + S: Into<ScopedSupercow<'s, Directory<'d>>>, { let dir = directory.into(); Filenames::from_ptr( diff --git a/src/filenames.rs b/src/filenames.rs index ad4c3e9..ce06289 100644 --- a/src/filenames.rs +++ b/src/filenames.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use supercow::Phantomcow; use crate::ffi; +use crate::utils::ScopedPhantomcow; pub trait FilenamesOwner {} @@ -30,7 +31,7 @@ where O: FilenamesOwner, { pub(crate) handle: FilenamesPtr, - pub(crate) marker: Phantomcow<'o, O>, + pub(crate) marker: ScopedPhantomcow<'o, O>, } impl<'o, O> Filenames<'o, O> @@ -39,7 +40,7 @@ where { pub fn from_ptr<P>(ptr: *mut ffi::notmuch_filenames_t, owner: P) -> Filenames<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Filenames { handle: FilenamesPtr { ptr }, @@ -26,11 +26,10 @@ pub use crate::directory::{Directory, DirectoryExt}; pub use crate::error::Error; pub use crate::filenames::{Filenames, FilenamesOwner}; pub use crate::message::{Message, MessageExt, MessageOwner}; -pub use crate::messages::{Messages, MessagesExt, MessagesOwner}; +pub use crate::messages::{Messages, MessagesExt}; pub use crate::query::{Query, QueryExt}; pub use crate::tags::{Tags, TagsExt, TagsOwner}; pub use crate::thread::{Thread, ThreadExt, ThreadOwner}; -pub use crate::threads::{Threads, ThreadsExt, ThreadsOwner}; +pub use crate::threads::{Threads, ThreadsExt}; pub use crate::ffi::{DatabaseMode, Sort}; -pub use crate::utils::{StreamingIterator, StreamingIteratorExt}; diff --git a/src/message.rs b/src/message.rs index b4bb581..baa638d 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,43 +1,33 @@ use std::ffi::CString; -use std::ops::Drop; use std::path::PathBuf; -use supercow::{Phantomcow, Supercow}; +use supercow::{Supercow}; use crate::error::{Error, Result}; use crate::ffi; -use crate::utils::ToStr; +use crate::utils::{ToStr, ScopedPhantomcow, ScopedSupercow}; use crate::Filenames; use crate::FilenamesOwner; use crate::Messages; -use crate::MessagesOwner; use crate::Tags; use crate::TagsOwner; -pub trait MessageOwner {} +pub trait MessageOwner: Send + Sync {} #[derive(Debug)] pub(crate) struct MessagePtr { pub ptr: *mut ffi::notmuch_message_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 MessagePtr { -// fn drop(&mut self) { -// unsafe { ffi::notmuch_message_destroy(self.ptr) }; -// } -// } - #[derive(Debug)] pub struct Message<'o, O> where O: MessageOwner, { pub(crate) handle: MessagePtr, - marker: Phantomcow<'o, O>, + marker: ScopedPhantomcow<'o, O>, } -impl<'o, O> MessagesOwner for Message<'o, O> where O: MessageOwner + 'o {} +impl<'o, O> MessageOwner for Message<'o, O> where O: MessageOwner + 'o {} impl<'o, O> FilenamesOwner for Message<'o, O> where O: MessageOwner + 'o {} impl<'o, O> TagsOwner for Message<'o, O> where O: MessageOwner + 'o {} @@ -47,7 +37,7 @@ where { pub fn from_ptr<P>(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Message { handle: MessagePtr { ptr }, @@ -128,7 +118,7 @@ where { fn tags<'s, S>(message: S) -> Tags<'s, Message<'o, O>> where - S: Into<Supercow<'s, Message<'o, O>>>, + S: Into<ScopedSupercow<'s, Message<'o, O>>>, { let messageref = message.into(); Tags::from_ptr( @@ -139,7 +129,7 @@ where fn replies<'s, S>(message: S) -> Messages<'s, Message<'o, O>> where - S: Into<Supercow<'s, Message<'o, O>>>, + S: Into<ScopedSupercow<'s, Message<'o, O>>>, { let messageref = message.into(); Messages::from_ptr( @@ -150,7 +140,7 @@ where fn filenames<'s, S>(message: S) -> Filenames<'s, Message<'o, O>> where - S: Into<Supercow<'s, Message<'o, O>>>, + S: Into<ScopedSupercow<'s, Message<'o, O>>>, { let messageref = message.into(); Filenames::from_ptr( diff --git a/src/messages.rs b/src/messages.rs index 88c52ec..3082512 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -3,14 +3,12 @@ use std::ops::Drop; use supercow::{Phantomcow, Supercow}; use crate::ffi; -use crate::utils::{StreamingIterator, StreamingIteratorExt}; +use crate::utils::{ScopedSupercow, ScopedPhantomcow}; use crate::Message; use crate::MessageOwner; use crate::Tags; use crate::TagsOwner; -pub trait MessagesOwner {} - #[derive(Debug)] pub struct MessagesPtr { pub ptr: *mut ffi::notmuch_messages_t, @@ -18,12 +16,6 @@ pub struct MessagesPtr { impl Drop for MessagesPtr { fn drop(self: &mut Self) { - let valid = unsafe { ffi::notmuch_messages_valid(self.ptr) }; - - if valid == 0 { - return; - } - unsafe { ffi::notmuch_messages_destroy(self.ptr) }; } } @@ -31,19 +23,19 @@ impl Drop for MessagesPtr { #[derive(Debug)] pub struct Messages<'o, O> where - O: MessagesOwner, + O: MessageOwner, { pub(crate) handle: MessagesPtr, - marker: Phantomcow<'o, O>, + marker: ScopedPhantomcow<'o, O>, } impl<'o, O> Messages<'o, O> where - O: MessagesOwner + 'o, + O: MessageOwner + 'o, { pub(crate) fn from_ptr<P>(ptr: *mut ffi::notmuch_messages_t, owner: P) -> Messages<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Messages { handle: MessagesPtr { ptr }, @@ -52,12 +44,12 @@ where } } -impl<'o, O> MessageOwner for Messages<'o, O> where O: MessagesOwner + 'o {} -impl<'o, O> TagsOwner for Messages<'o, O> where O: MessagesOwner + 'o {} +impl<'o, O> MessageOwner for Messages<'o, O> where O: MessageOwner + 'o {} +impl<'o, O> TagsOwner for Messages<'o, O> where O: MessageOwner + 'o {} impl<'o, O> Messages<'o, O> where - O: MessagesOwner + 'o, + O: MessageOwner + 'o, { /** * Return a list of tags from all messages. @@ -80,47 +72,14 @@ where } } -impl<'s, 'o: 's, O> StreamingIterator<'s, Message<'s, Self>> for Messages<'o, O> -where - O: MessagesOwner + 'o, -{ - fn next(&'s mut self) -> Option<Message<'s, Self>> { - <Self as StreamingIteratorExt<'s, Message<'s, Self>>>::next(Supercow::borrowed(self)) - } -} - pub trait MessagesExt<'o, O> where - O: MessagesOwner + 'o, + O: MessageOwner + 'o, { } -impl<'o, O> MessagesExt<'o, O> for Messages<'o, O> where O: MessagesOwner + 'o {} +impl<'o, O> MessagesExt<'o, O> for Messages<'o, O> where O: MessageOwner + 'o {} -impl<'s, 'o: 's, O> StreamingIteratorExt<'s, Message<'s, Self>> for Messages<'o, O> -where - O: MessagesOwner + 'o, -{ - fn next<S>(messages: S) -> Option<Message<'s, Self>> - where - S: Into<Supercow<'s, Messages<'o, O>>>, - { - let messagesref = messages.into(); - let valid = unsafe { ffi::notmuch_messages_valid(messagesref.handle.ptr) }; - - if valid == 0 { - return None; - } - - let cmsg = unsafe { - let msg = ffi::notmuch_messages_get(messagesref.handle.ptr); - ffi::notmuch_messages_move_to_next(messagesref.handle.ptr); - msg - }; - - Some(Message::from_ptr(cmsg, Supercow::phantom(messagesref))) - } -} -unsafe impl<'o, O> Send for Messages<'o, O> where O: MessagesOwner + 'o {} -unsafe impl<'o, O> Sync for Messages<'o, O> where O: MessagesOwner + 'o {} +unsafe impl<'o, O> Send for Messages<'o, O> where O: MessageOwner + 'o {} +unsafe impl<'o, O> Sync for Messages<'o, O> where O: MessageOwner + 'o {} diff --git a/src/query.rs b/src/query.rs index 3dba264..dbe5400 100644 --- a/src/query.rs +++ b/src/query.rs @@ -8,9 +8,10 @@ use crate::ffi; use crate::ffi::Sort; use crate::Database; use crate::Messages; -use crate::MessagesOwner; +use crate::MessageOwner; use crate::Threads; -use crate::ThreadsOwner; +use crate::ThreadOwner; +use crate::utils::{ScopedSupercow, ScopedPhantomcow}; #[derive(Debug)] pub(crate) struct QueryPtr { @@ -29,8 +30,8 @@ pub struct Query<'d> { marker: Phantomcow<'d, Database>, } -impl<'d> ThreadsOwner for Query<'d> {} -impl<'d> MessagesOwner for Query<'d> {} +impl<'d> ThreadOwner for Query<'d> {} +impl<'d> MessageOwner for Query<'d> {} impl<'d> Query<'d> { pub(crate) fn from_ptr<O>(ptr: *mut ffi::notmuch_query_t, owner: O) -> Query<'d> @@ -102,7 +103,7 @@ impl<'d> Query<'d> { pub trait QueryExt<'d> { fn search_threads<'q, Q>(query: Q) -> Result<Threads<'q, Query<'d>>> where - Q: Into<Supercow<'q, Query<'d>>>, + Q: Into<ScopedSupercow<'q, Query<'d>>>, { let queryref = query.into(); @@ -110,12 +111,12 @@ pub trait QueryExt<'d> { unsafe { ffi::notmuch_query_search_threads(queryref.handle.ptr, &mut thrds) } .as_result()?; - Ok(Threads::from_ptr(thrds, Supercow::phantom(queryref))) + Ok(Threads::from_ptr(thrds, ScopedSupercow::phantom(queryref))) } fn search_messages<'q, Q>(query: Q) -> Result<Messages<'q, Query<'d>>> where - Q: Into<Supercow<'q, Query<'d>>>, + Q: Into<ScopedSupercow<'q, Query<'d>>>, { let queryref = query.into(); @@ -123,7 +124,7 @@ pub trait QueryExt<'d> { unsafe { ffi::notmuch_query_search_messages(queryref.handle.ptr, &mut msgs) } .as_result()?; - Ok(Messages::from_ptr(msgs, Supercow::phantom(queryref))) + Ok(Messages::from_ptr(msgs, ScopedSupercow::phantom(queryref))) } } diff --git a/src/tags.rs b/src/tags.rs index f400f63..bf7b777 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -5,6 +5,7 @@ use std::ops::Drop; use supercow::Phantomcow; use crate::ffi; +use crate::utils::ScopedPhantomcow; pub trait TagsOwner {} @@ -22,7 +23,7 @@ impl Drop for TagsPtr { #[derive(Debug)] pub struct Tags<'o, Owner: TagsOwner> { handle: TagsPtr, - marker: Phantomcow<'o, Owner>, + marker: ScopedPhantomcow<'o, Owner>, } impl<'o, O> Tags<'o, O> @@ -31,7 +32,7 @@ where { pub fn from_ptr<P>(ptr: *mut ffi::notmuch_tags_t, owner: P) -> Tags<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Tags { handle: TagsPtr { ptr }, 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<P>(ptr: *mut ffi::notmuch_thread_t, owner: P) -> Thread<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Thread { handle: ThreadPtr { ptr }, @@ -111,23 +103,23 @@ where { fn tags<'s, S>(thread: S) -> Tags<'s, Thread<'o, O>> where - S: Into<Supercow<'s, Thread<'o, O>>>, + S: Into<ScopedSupercow<'s, Thread<'o, O>>>, { 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<Supercow<'s, Thread<'o, O>>>, + S: Into<ScopedSupercow<'s, Thread<'o, O>>>, { 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<Supercow<'s, Thread<'o, O>>>, + S: Into<ScopedSupercow<'s, Thread<'o, O>>>, { let threadref = thread.into(); Messages::from_ptr( unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) }, - Supercow::phantom(threadref), + ScopedSupercow::phantom(threadref), ) } } diff --git a/src/threads.rs b/src/threads.rs index 2bd3d24..d182625 100644 --- a/src/threads.rs +++ b/src/threads.rs @@ -1,13 +1,12 @@ use std::ops::Drop; use supercow::{Phantomcow, Supercow}; -use crate::utils::{StreamingIterator, StreamingIteratorExt}; use crate::ffi; -use crate::thread::ThreadOwner; +use crate::thread::{ThreadOwner, ThreadPtr}; use crate::Thread; +use crate::utils::{ScopedPhantomcow, ScopedSupercow}; -pub trait ThreadsOwner {} #[derive(Debug)] pub(crate) struct ThreadsPtr { @@ -23,21 +22,19 @@ impl Drop for ThreadsPtr { #[derive(Debug)] pub struct Threads<'o, O> where - O: ThreadsOwner, + O: ThreadOwner, { handle: ThreadsPtr, - marker: Phantomcow<'o, O>, + marker: ScopedPhantomcow<'o, O>, } -impl<'o, O> ThreadOwner for Threads<'o, O> where O: ThreadsOwner + 'o {} - impl<'o, O> Threads<'o, O> where - O: ThreadsOwner + 'o, + O: ThreadOwner + 'o, { pub fn from_ptr<P>(ptr: *mut ffi::notmuch_threads_t, owner: P) -> Threads<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Threads { handle: ThreadsPtr { ptr }, @@ -46,47 +43,38 @@ where } } -impl<'s, 'o: 's, O> StreamingIterator<'s, Thread<'s, Self>> for Threads<'o, O> +impl<'o, O> Iterator for Threads<'o, O> where - O: ThreadsOwner + 'o, + O: ThreadOwner, { - fn next(&'s mut self) -> Option<Thread<'s, Self>> { - <Self as StreamingIteratorExt<'s, Thread<'s, Self>>>::next(Supercow::borrowed(self)) - } -} + type Item = Thread<'o, O>; -pub trait ThreadsExt<'o, O> -where - O: ThreadsOwner + 'o, -{ -} - -impl<'o, O> ThreadsExt<'o, O> for Threads<'o, O> where O: ThreadsOwner + 'o {} - -impl<'s, 'o: 's, O> StreamingIteratorExt<'s, Thread<'s, Self>> for Threads<'o, O> -where - O: ThreadsOwner + 'o, -{ - fn next<S>(threads: S) -> Option<Thread<'s, Self>> - where - S: Into<Supercow<'s, Threads<'o, O>>>, - { - let threadsref = threads.into(); - let valid = unsafe { ffi::notmuch_threads_valid(threadsref.handle.ptr) }; + fn next(&mut self) -> Option<Thread<'o, O>> { + let valid = unsafe { ffi::notmuch_threads_valid(self.handle.ptr) }; if valid == 0 { return None; } - let cmsg = unsafe { - let msg = ffi::notmuch_threads_get(threadsref.handle.ptr); - ffi::notmuch_threads_move_to_next(threadsref.handle.ptr); - msg + let cthrd = unsafe { + let thrd = ffi::notmuch_threads_get(self.handle.ptr); + ffi::notmuch_threads_move_to_next(self.handle.ptr); + thrd }; - Some(Thread::from_ptr(cmsg, Supercow::phantom(threadsref))) + Some(Thread::from_ptr(cthrd, ScopedPhantomcow::<'o, O>::share(&mut self.marker))) } } -unsafe impl<'o, O> Send for Threads<'o, O> where O: ThreadsOwner + 'o {} -unsafe impl<'o, O> Sync for Threads<'o, O> where O: ThreadsOwner + 'o {} + +pub trait ThreadsExt<'o, O> +where + O: ThreadOwner + 'o, +{ +} + +impl<'o, O> ThreadsExt<'o, O> for Threads<'o, O> where O: ThreadOwner + 'o {} + + +unsafe impl<'o, O> Send for Threads<'o, O> where O: ThreadOwner + 'o {} +unsafe impl<'o, O> Sync for Threads<'o, O> where O: ThreadOwner + 'o {} diff --git a/src/utils.rs b/src/utils.rs index be5f66c..353093f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,7 +1,8 @@ use libc; use std::{ffi, str}; -use supercow::Supercow; +use supercow::{Supercow, DefaultFeatures, NonSyncFeatures}; +use supercow::ext::{BoxedStorage}; pub trait ToStr { fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error>; @@ -23,17 +24,18 @@ impl ToString for *const libc::c_char { } } -/// A streaming iterator, as found in https://github.com/emk/rust-streaming -pub trait StreamingIterator<'a, T> { - /// Return either the next item in the sequence, or `None` if all items - /// have been consumed. - fn next(&'a mut self) -> Option<T>; -} +pub type ScopedNonSyncSupercow<'a, OWNED, BORROWED = OWNED> = + Supercow<'a, OWNED, BORROWED, + Box<NonSyncFeatures<'a> + 'a>, + BoxedStorage>; + +pub type ScopedPhantomcow<'a, OWNED, BORROWED = OWNED, + SHARED = Box<DefaultFeatures<'a> + 'a>, + STORAGE = BoxedStorage> = + Supercow<'a, OWNED, BORROWED, SHARED, STORAGE, ()>; + +pub type ScopedSupercow<'a, OWNED, BORROWED = OWNED, SHARED = Box<DefaultFeatures<'a> + 'a>> = + Supercow<'a, OWNED, BORROWED, SHARED, BoxedStorage>; + + -pub trait StreamingIteratorExt<'a, T> { - /// Return either the next item in the sequence, or `None` if all items - /// have been consumed. - fn next<S: Into<Supercow<'a, Self>>>(s: S) -> Option<T> - where - Self: Sized + 'a; -} diff --git a/tests/main.rs b/tests/main.rs index def2e5f..8a857dd 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -3,7 +3,6 @@ use notmuch; use std::sync::Arc; -use notmuch::StreamingIteratorExt; use notmuch::{Query, QueryExt, Threads}; fn main() { @@ -30,9 +29,9 @@ fn main() { // let mut threads = db.create_query(&"".to_string()).unwrap().search_threads().unwrap(); - let threads = Arc::new(<Query as QueryExt>::search_threads(query).unwrap()); + let mut threads = Arc::new(<Query as QueryExt>::search_threads(query).unwrap()); - while let Some(thread) = <Threads<_> as StreamingIteratorExt<_>>::next(threads.clone()) + for thread in Arc::get_mut(&mut threads).unwrap() { println!("thread {:?} {:?}", thread.subject(), thread.authors()); } |
