aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-15 07:19:38 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-15 07:19:38 +0100
commit16704244a19bf896ce2d42c4dfb63feb5ac319c5 (patch)
treed984b1ce27978b62d7cbec6c56ab0a912c022df9
parent4b19b951dd2fb7aa7bc662170c91401f2e8fac3b (diff)
downloadmail-16704244a19bf896ce2d42c4dfb63feb5ac319c5.tar.gz
Threads are only ever owned by a Query. Nothing else
-rw-r--r--src/database.rs2
-rw-r--r--src/directory.rs2
-rw-r--r--src/filenames.rs2
-rw-r--r--src/lib.rs2
-rw-r--r--src/messages.rs5
-rw-r--r--src/query.rs10
-rw-r--r--src/tags.rs2
-rw-r--r--src/thread.rs56
-rw-r--r--src/threads.rs40
-rw-r--r--src/utils.rs10
10 files changed, 63 insertions, 68 deletions
diff --git a/src/database.rs b/src/database.rs
index 0ff443a..19d33c7 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -16,7 +16,7 @@ use crate::Directory;
use crate::Query;
use crate::Tags;
use crate::TagsOwner;
-use crate::utils::{ScopedSupercow, ScopedPhantomcow};
+use crate::utils::ScopedSupercow;
// Re-exported under database module for pretty namespacin'.
pub use crate::ffi::DatabaseMode;
diff --git a/src/directory.rs b/src/directory.rs
index 09baf77..6402902 100644
--- a/src/directory.rs
+++ b/src/directory.rs
@@ -1,5 +1,5 @@
use std::ops::Drop;
-use supercow::{Phantomcow, Supercow};
+use supercow::Supercow;
use crate::ffi;
use crate::Database;
diff --git a/src/filenames.rs b/src/filenames.rs
index ce06289..24ce513 100644
--- a/src/filenames.rs
+++ b/src/filenames.rs
@@ -3,8 +3,6 @@ use std::iter::Iterator;
use std::ops::Drop;
use std::path::PathBuf;
-use supercow::Phantomcow;
-
use crate::ffi;
use crate::utils::ScopedPhantomcow;
diff --git a/src/lib.rs b/src/lib.rs
index 2dd6958..8f60a3f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,7 +29,7 @@ pub use crate::message::{Message, MessageExt, MessageOwner};
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::thread::{Thread, ThreadExt};
pub use crate::threads::{Threads, ThreadsExt};
pub use crate::ffi::{DatabaseMode, Sort};
diff --git a/src/messages.rs b/src/messages.rs
index 3082512..69b6dcc 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -1,10 +1,7 @@
use std::ops::Drop;
-use supercow::{Phantomcow, Supercow};
-
use crate::ffi;
-use crate::utils::{ScopedSupercow, ScopedPhantomcow};
-use crate::Message;
+use crate::utils::ScopedPhantomcow;
use crate::MessageOwner;
use crate::Tags;
use crate::TagsOwner;
diff --git a/src/query.rs b/src/query.rs
index dbe5400..9a04c7a 100644
--- a/src/query.rs
+++ b/src/query.rs
@@ -10,8 +10,7 @@ use crate::Database;
use crate::Messages;
use crate::MessageOwner;
use crate::Threads;
-use crate::ThreadOwner;
-use crate::utils::{ScopedSupercow, ScopedPhantomcow};
+use crate::utils::ScopedSupercow;
#[derive(Debug)]
pub(crate) struct QueryPtr {
@@ -30,7 +29,6 @@ pub struct Query<'d> {
marker: Phantomcow<'d, Database>,
}
-impl<'d> ThreadOwner for Query<'d> {}
impl<'d> MessageOwner for Query<'d> {}
impl<'d> Query<'d> {
@@ -88,8 +86,8 @@ impl<'d> Query<'d> {
Ok(cnt)
}
- pub fn search_threads<'q>(self: &'d Self) -> Result<Threads<'q, Self>> {
- <Query<'_> as QueryExt>::search_threads(self)
+ pub fn search_threads<'q>(self: &'d Self) -> Result<Threads<'d, 'q>> {
+ <Query<'d> as QueryExt>::search_threads(self)
}
pub fn count_threads(self: &Self) -> Result<u32> {
@@ -101,7 +99,7 @@ impl<'d> Query<'d> {
}
pub trait QueryExt<'d> {
- fn search_threads<'q, Q>(query: Q) -> Result<Threads<'q, Query<'d>>>
+ fn search_threads<'q, Q>(query: Q) -> Result<Threads<'d, 'q>>
where
Q: Into<ScopedSupercow<'q, Query<'d>>>,
{
diff --git a/src/tags.rs b/src/tags.rs
index bf7b777..215bb8a 100644
--- a/src/tags.rs
+++ b/src/tags.rs
@@ -2,8 +2,6 @@ use std::ffi::CStr;
use std::iter::Iterator;
use std::ops::Drop;
-use supercow::Phantomcow;
-
use crate::ffi;
use crate::utils::ScopedPhantomcow;
diff --git a/src/thread.rs b/src/thread.rs
index 9569cbc..b3cd151 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -1,5 +1,4 @@
use std::ops::Drop;
-use supercow::{Phantomcow, Supercow};
use crate::ffi;
use crate::utils::{ToStr, ScopedSupercow, ScopedPhantomcow};
@@ -7,33 +6,38 @@ use crate::Messages;
use crate::MessageOwner;
use crate::Tags;
use crate::TagsOwner;
-
-pub trait ThreadOwner: Send + Sync {}
+use crate::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<'o, O>
+pub struct Thread<'d, 'q>
where
- O: ThreadOwner,
+ 'd: 'q
{
pub(crate) handle: ThreadPtr,
- pub(crate) marker: ScopedPhantomcow<'o, O>,
+ pub(crate) marker: ScopedPhantomcow<'q, Query<'d>>,
}
-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<'d, 'q> MessageOwner for Thread<'d, 'q> where 'd: 'q {}
+impl<'d, 'q> TagsOwner for Thread<'d, 'q> where 'd: 'q {}
-impl<'o, O> Thread<'o, O>
+impl<'d, 'q> Thread<'d, 'q>
where
- O: ThreadOwner + 'o,
+ 'd: 'q
{
- pub fn from_ptr<P>(ptr: *mut ffi::notmuch_thread_t, owner: P) -> Thread<'o, O>
+ pub fn from_ptr<P>(ptr: *mut ffi::notmuch_thread_t, owner: P) -> Thread<'d, 'q>
where
- P: Into<ScopedPhantomcow<'o, O>>,
+ P: Into<ScopedPhantomcow<'q, Query<'d>>>,
{
Thread {
handle: ThreadPtr { ptr },
@@ -56,17 +60,17 @@ where
}
pub fn toplevel_messages(self: &Self) -> Messages<'_, Self> {
- <Self as ThreadExt<'o, O>>::toplevel_messages(self)
+ <Self as ThreadExt<'d, 'q>>::toplevel_messages(self)
}
/// Get a `Messages` iterator for all messages in 'thread' in
/// oldest-first order.
pub fn messages(self: &Self) -> Messages<'_, Self> {
- <Self as ThreadExt<'o, O>>::messages(self)
+ <Self as ThreadExt<'d, 'q>>::messages(self)
}
pub fn tags(&self) -> Tags<'_, Self> {
- <Self as ThreadExt<'o, O>>::tags(self)
+ <Self as ThreadExt<'d, 'q>>::tags(self)
}
pub fn subject(self: &Self) -> String {
@@ -97,13 +101,13 @@ where
}
}
-pub trait ThreadExt<'o, O>
+pub trait ThreadExt<'d, 'q>
where
- O: ThreadOwner + 'o,
+ 'd: 'q
{
- fn tags<'s, S>(thread: S) -> Tags<'s, Thread<'o, O>>
+ fn tags<'s, S>(thread: S) -> Tags<'s, Thread<'d, 'q>>
where
- S: Into<ScopedSupercow<'s, Thread<'o, O>>>,
+ S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
{
let threadref = thread.into();
Tags::from_ptr(
@@ -112,9 +116,9 @@ where
)
}
- fn toplevel_messages<'s, S>(thread: S) -> Messages<'s, Thread<'o, O>>
+ fn toplevel_messages<'s, S>(thread: S) -> Messages<'s, Thread<'d, 'q>>
where
- S: Into<ScopedSupercow<'s, Thread<'o, O>>>,
+ S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
{
let threadref = thread.into();
Messages::from_ptr(
@@ -125,9 +129,9 @@ where
/// Get a `Messages` iterator for all messages in 'thread' in
/// oldest-first order.
- fn messages<'s, S>(thread: S) -> Messages<'s, Thread<'o, O>>
+ fn messages<'s, S>(thread: S) -> Messages<'s, Thread<'d, 'q>>
where
- S: Into<ScopedSupercow<'s, Thread<'o, O>>>,
+ S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
{
let threadref = thread.into();
Messages::from_ptr(
@@ -137,7 +141,7 @@ where
}
}
-impl<'o, O> ThreadExt<'o, O> for Thread<'o, O> where O: ThreadOwner + 'o {}
+impl<'d, 'q> ThreadExt<'d, 'q> for Thread<'d, 'q> where 'd: 'q {}
-unsafe impl<'o, O> Send for Thread<'o, O> where O: ThreadOwner + 'o {}
-unsafe impl<'o, O> Sync for Thread<'o, O> where O: ThreadOwner + 'o {}
+unsafe impl<'d, 'q> Send for Thread<'d, 'q> where 'd: 'q {}
+unsafe impl<'d, 'q> Sync for Thread<'d, 'q> where 'd: 'q {}
diff --git a/src/threads.rs b/src/threads.rs
index d182625..4aa5a9b 100644
--- a/src/threads.rs
+++ b/src/threads.rs
@@ -1,11 +1,9 @@
use std::ops::Drop;
-use supercow::{Phantomcow, Supercow};
-
use crate::ffi;
-use crate::thread::{ThreadOwner, ThreadPtr};
use crate::Thread;
-use crate::utils::{ScopedPhantomcow, ScopedSupercow};
+use crate::Query;
+use crate::utils::ScopedPhantomcow;
#[derive(Debug)]
@@ -20,21 +18,21 @@ impl Drop for ThreadsPtr {
}
#[derive(Debug)]
-pub struct Threads<'o, O>
+pub struct Threads<'d, 'q>
where
- O: ThreadOwner,
+ 'd: 'q
{
handle: ThreadsPtr,
- marker: ScopedPhantomcow<'o, O>,
+ marker: ScopedPhantomcow<'q, Query<'d>>,
}
-impl<'o, O> Threads<'o, O>
+impl<'d, 'q> Threads<'d, 'q>
where
- O: ThreadOwner + 'o,
+ 'd: 'q,
{
- pub fn from_ptr<P>(ptr: *mut ffi::notmuch_threads_t, owner: P) -> Threads<'o, O>
+ pub fn from_ptr<P>(ptr: *mut ffi::notmuch_threads_t, owner: P) -> Threads<'d, 'q>
where
- P: Into<ScopedPhantomcow<'o, O>>,
+ P: Into<ScopedPhantomcow<'q, Query<'d>>>,
{
Threads {
handle: ThreadsPtr { ptr },
@@ -43,13 +41,13 @@ where
}
}
-impl<'o, O> Iterator for Threads<'o, O>
+impl<'d, 'q> Iterator for Threads<'d, 'q>
where
- O: ThreadOwner,
+ 'd: 'q,
{
- type Item = Thread<'o, O>;
+ type Item = Thread<'d, 'q>;
- fn next(&mut self) -> Option<Thread<'o, O>> {
+ fn next(&mut self) -> Option<Self::Item> {
let valid = unsafe { ffi::notmuch_threads_valid(self.handle.ptr) };
if valid == 0 {
@@ -62,19 +60,19 @@ where
thrd
};
- Some(Thread::from_ptr(cthrd, ScopedPhantomcow::<'o, O>::share(&mut self.marker)))
+ Some(Thread::from_ptr(cthrd, ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker)))
}
}
-pub trait ThreadsExt<'o, O>
+pub trait ThreadsExt<'d, 'q>
where
- O: ThreadOwner + 'o,
+ 'd: 'q,
{
}
-impl<'o, O> ThreadsExt<'o, O> for Threads<'o, O> where O: ThreadOwner + 'o {}
+impl<'d, 'q> ThreadsExt<'d, 'q> for Threads<'d, 'q> where 'd: 'q {}
-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 {}
+unsafe impl<'d, 'q> Send for Threads<'d, 'q> where 'd: 'q {}
+unsafe impl<'d, 'q> Sync for Threads<'d, 'q> where 'd: 'q {}
diff --git a/src/utils.rs b/src/utils.rs
index 353093f..409534c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -24,10 +24,10 @@ impl ToString for *const libc::c_char {
}
}
-pub type ScopedNonSyncSupercow<'a, OWNED, BORROWED = OWNED> =
- Supercow<'a, OWNED, BORROWED,
- Box<NonSyncFeatures<'a> + 'a>,
- BoxedStorage>;
+// 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>,
@@ -39,3 +39,5 @@ pub type ScopedSupercow<'a, OWNED, BORROWED = OWNED, SHARED = Box<DefaultFeature
+
+