aboutsummaryrefslogtreecommitdiffstats
path: root/src/threads.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/threads.rs')
-rw-r--r--src/threads.rs68
1 files changed, 28 insertions, 40 deletions
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 {}