aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-17 15:52:59 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-17 15:52:59 +0100
commit0d510d55c4238ff0a1175985b27ca38c71a3cfc2 (patch)
tree49b38f55d48786cf7e31746c5ae292995f8f502f
parent895fee066eed58e18c2633cf7d0fa870a65ac06d (diff)
downloadmail-0d510d55c4238ff0a1175985b27ca38c71a3cfc2.tar.gz
link lifetime of message to Query
-rw-r--r--src/lib.rs2
-rw-r--r--src/message.rs71
-rw-r--r--src/messages.rs43
-rw-r--r--src/query.rs4
-rw-r--r--src/thread.rs60
-rw-r--r--src/utils.rs4
6 files changed, 96 insertions, 88 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ef8cc33..7948f77 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,4 +32,4 @@ pub use tags::{Tags, TagsExt, TagsOwner};
pub use thread::{Thread, ThreadExt};
pub use threads::{Threads, ThreadsExt};
-pub use ffi::{DatabaseMode, Sort}; \ No newline at end of file
+pub use ffi::{DatabaseMode, Sort};
diff --git a/src/message.rs b/src/message.rs
index 8cc7af2..80e7c46 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -10,6 +10,7 @@ use FilenamesOwner;
use Messages;
use Tags;
use TagsOwner;
+use Query;
pub trait MessageOwner: Send + Sync {}
@@ -19,25 +20,25 @@ pub(crate) struct MessagePtr {
}
#[derive(Debug)]
-pub struct Message<'o, O>
+pub struct Message<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
pub(crate) handle: MessagePtr,
- marker: ScopedPhantomcow<'o, O>,
+ marker: ScopedPhantomcow<'q, Query<'d>>,
}
-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 {}
+impl<'d, 'q> MessageOwner for Message<'d, 'q> where 'd: 'q {}
+impl<'d, 'q> FilenamesOwner for Message<'d, 'q> where 'd: 'q {}
+impl<'d, 'q> TagsOwner for Message<'d, 'q> where 'd: 'q {}
-impl<'o, O> Message<'o, O>
+impl<'d, 'q> Message<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
- pub fn from_ptr<P>(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'o, O>
+ pub fn from_ptr<P>(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'d, 'q>
where
- P: Into<ScopedPhantomcow<'o, O>>,
+ P: Into<ScopedPhantomcow<'q, Query<'d>>>,
{
Message {
handle: MessagePtr { ptr },
@@ -55,8 +56,12 @@ where
tid.to_str().unwrap().to_string()
}
- pub fn replies(self: &Self) -> Messages<Self> {
- <Self as MessageExt<'o, O>>::replies(self)
+ pub fn replies(self: &mut Self) -> Messages<'d, 'q>
+ {
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_message_get_replies(self.handle.ptr) },
+ ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker),
+ )
}
#[cfg(feature = "v0_26")]
@@ -65,7 +70,7 @@ where
}
pub fn filenames(self: &Self) -> Filenames<Self> {
- <Self as MessageExt<'o, O>>::filenames(self)
+ <Self as MessageExt<'d, 'q>>::filenames(self)
}
pub fn filename(self: &Self) -> PathBuf {
@@ -94,7 +99,7 @@ where
}
pub fn tags(&self) -> Tags<Self> {
- <Self as MessageExt<'o, O>>::tags(self)
+ <Self as MessageExt<'d, 'q>>::tags(self)
}
pub fn add_tag(self: &Self, tag: &str) -> Result<()> {
@@ -112,13 +117,13 @@ where
}
}
-pub trait MessageExt<'o, O>
+pub trait MessageExt<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
- fn tags<'s, S>(message: S) -> Tags<'s, Message<'o, O>>
+ fn tags<'s, S>(message: S) -> Tags<'s, Message<'d, 'q>>
where
- S: Into<ScopedSupercow<'s, Message<'o, O>>>,
+ S: Into<ScopedSupercow<'s, Message<'d, 'q>>>,
{
let messageref = message.into();
Tags::from_ptr(
@@ -127,20 +132,20 @@ where
)
}
- fn replies<'s, S>(message: S) -> Messages<'s, Message<'o, O>>
- where
- S: Into<ScopedSupercow<'s, Message<'o, O>>>,
- {
- let messageref = message.into();
- Messages::from_ptr(
- unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) },
- Supercow::phantom(messageref),
- )
- }
+ // fn replies<'s, S>(message: S) -> Messages<'d, 'q>
+ // where
+ // S: Into<ScopedSupercow<'s, Message<'d, 'q>>>,
+ // {
+ // let messageref = message.into();
+ // Messages::from_ptr(
+ // unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) },
+ // Supercow::phantom(messageref),
+ // )
+ // }
- fn filenames<'s, S>(message: S) -> Filenames<'s, Message<'o, O>>
+ fn filenames<'s, S>(message: S) -> Filenames<'s, Message<'d, 'q>>
where
- S: Into<ScopedSupercow<'s, Message<'o, O>>>,
+ S: Into<ScopedSupercow<'s, Message<'d, 'q>>>,
{
let messageref = message.into();
Filenames::from_ptr(
@@ -150,7 +155,7 @@ where
}
}
-impl<'o, O> MessageExt<'o, O> for Message<'o, O> where O: MessageOwner + 'o {}
+impl<'d, 'q> MessageExt<'d, 'q> for Message<'d, 'q> where 'd: 'q {}
-unsafe impl<'o, O> Send for Message<'o, O> where O: MessageOwner + 'o {}
-unsafe impl<'o, O> Sync for Message<'o, O> where O: MessageOwner + 'o {}
+unsafe impl<'d, 'q> Send for Message<'d, 'q> where 'd: 'q {}
+unsafe impl<'d, 'q> Sync for Message<'d, 'q> where 'd: 'q {}
diff --git a/src/messages.rs b/src/messages.rs
index db92f73..2401293 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -6,6 +6,7 @@ use MessageOwner;
use Message;
use Tags;
use TagsOwner;
+use Query;
#[derive(Debug)]
pub struct MessagesPtr {
@@ -19,21 +20,21 @@ impl Drop for MessagesPtr {
}
#[derive(Debug)]
-pub struct Messages<'o, O>
+pub struct Messages<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
pub(crate) handle: MessagesPtr,
- marker: ScopedPhantomcow<'o, O>,
+ marker: ScopedPhantomcow<'q, Query<'d>>,
}
-impl<'o, O> Messages<'o, O>
+impl<'d, 'q> Messages<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
- pub(crate) fn from_ptr<P>(ptr: *mut ffi::notmuch_messages_t, owner: P) -> Messages<'o, O>
+ pub(crate) fn from_ptr<P>(ptr: *mut ffi::notmuch_messages_t, owner: P) -> Messages<'d, 'q>
where
- P: Into<ScopedPhantomcow<'o, O>>,
+ P: Into<ScopedPhantomcow<'q, Query<'d>>>,
{
Messages {
handle: MessagesPtr { ptr },
@@ -42,12 +43,12 @@ where
}
}
-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<'d, 'q> MessageOwner for Messages<'d, 'q> where 'd: 'q {}
+impl<'d, 'q> TagsOwner for Messages<'d, 'q> where 'd: 'q {}
-impl<'o, O> Messages<'o, O>
+impl<'d, 'q> Messages<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
/**
* Return a list of tags from all messages.
@@ -62,7 +63,7 @@ where
*
* The function returns NULL on error.
*/
- pub fn collect_tags<'m>(self: &'o Self) -> Tags<'m, Self> {
+ pub fn collect_tags<'m>(self: &'m Self) -> Tags<'m, Self> {
Tags::from_ptr(
unsafe { ffi::notmuch_messages_collect_tags(self.handle.ptr) },
self,
@@ -70,11 +71,11 @@ where
}
}
-impl<'o, O> Iterator for Messages<'o, O>
+impl<'d, 'q> Iterator for Messages<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
- type Item = Message<'o, O>;
+ type Item = Message<'d, 'q>;
fn next(&mut self) -> Option<Self::Item> {
let valid = unsafe { ffi::notmuch_messages_valid(self.handle.ptr) };
@@ -89,20 +90,20 @@ where
thrd
};
- Some(Message::from_ptr(cthrd, ScopedPhantomcow::<'o, O>::share(&mut self.marker)))
+ Some(Message::from_ptr(cthrd, ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker)))
}
}
-pub trait MessagesExt<'o, O>
+pub trait MessagesExt<'d, 'q>
where
- O: MessageOwner + 'o,
+ 'd: 'q,
{
}
-impl<'o, O> MessagesExt<'o, O> for Messages<'o, O> where O: MessageOwner + 'o {}
+impl<'d, 'q> MessagesExt<'q, 'q> for Messages<'d, 'q> where 'd: 'q {}
-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 {}
+unsafe impl<'d, 'q> Send for Messages<'d, 'q> where 'd: 'q {}
+unsafe impl<'d, 'q> Sync for Messages<'d, 'q> where 'd: 'q {}
diff --git a/src/query.rs b/src/query.rs
index adbed58..97a3f52 100644
--- a/src/query.rs
+++ b/src/query.rs
@@ -75,7 +75,7 @@ impl<'d> Query<'d> {
}
/// Filter messages according to the query and return
- pub fn search_messages<'q>(self: &'d Self) -> Result<Messages<'q, Self>> {
+ pub fn search_messages<'q>(self: &'d Self) -> Result<Messages<'d, 'q>> {
<Query as QueryExt>::search_messages(self)
}
@@ -112,7 +112,7 @@ pub trait QueryExt<'d> {
Ok(Threads::from_ptr(thrds, ScopedSupercow::phantom(queryref)))
}
- fn search_messages<'q, Q>(query: Q) -> Result<Messages<'q, Query<'d>>>
+ fn search_messages<'q, Q>(query: Q) -> Result<Messages<'d, 'q>>
where
Q: Into<ScopedSupercow<'q, Query<'d>>>,
{
diff --git a/src/thread.rs b/src/thread.rs
index 137c936..20280e1 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -59,14 +59,20 @@ where
unsafe { ffi::notmuch_thread_get_total_files(self.handle.ptr) }
}
- pub fn toplevel_messages(self: &Self) -> Messages<'_, Self> {
- <Self as ThreadExt<'d, 'q>>::toplevel_messages(self)
+ pub fn toplevel_messages(self: &mut Self) -> Messages<'d, 'q> {
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_thread_get_toplevel_messages(self.handle.ptr) },
+ ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker),
+ )
}
/// Get a `Messages` iterator for all messages in 'thread' in
/// oldest-first order.
- pub fn messages(self: &Self) -> Messages<'_, Self> {
- <Self as ThreadExt<'d, 'q>>::messages(self)
+ pub fn messages(self: &mut Self) -> Messages<'d, 'q> {
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_thread_get_messages(self.handle.ptr) },
+ ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker),
+ )
}
pub fn tags(&self) -> Tags<'_, Self> {
@@ -116,29 +122,29 @@ where
)
}
- fn toplevel_messages<'s, S>(thread: S) -> Messages<'s, Thread<'d, 'q>>
- where
- S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
- {
- let threadref = thread.into();
- Messages::from_ptr(
- unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) },
- ScopedSupercow::phantom(threadref),
- )
- }
-
- /// Get a `Messages` iterator for all messages in 'thread' in
- /// oldest-first order.
- fn messages<'s, S>(thread: S) -> Messages<'s, Thread<'d, 'q>>
- where
- S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
- {
- let threadref = thread.into();
- Messages::from_ptr(
- unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) },
- ScopedSupercow::phantom(threadref),
- )
- }
+ // fn toplevel_messages<'s, S>(thread: S) -> Messages<'d, 'q>
+ // where
+ // S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
+ // {
+ // let threadref = thread.into();
+ // Messages::from_ptr(
+ // unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) },
+ // ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker),
+ // )
+ // }
+
+ // /// Get a `Messages` iterator for all messages in 'thread' in
+ // /// oldest-first order.
+ // fn messages<'s, S>(thread: S) -> Messages<'d, 'q>
+ // where
+ // S: Into<ScopedSupercow<'s, Thread<'d, 'q>>>,
+ // {
+ // let threadref = thread.into();
+ // Messages::from_ptr(
+ // unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) },
+ // ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker),
+ // )
+ // }
}
impl<'d, 'q> ThreadExt<'d, 'q> for Thread<'d, 'q> where 'd: 'q {}
diff --git a/src/utils.rs b/src/utils.rs
index 409534c..ab21d13 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -37,7 +37,3 @@ pub type ScopedPhantomcow<'a, OWNED, BORROWED = OWNED,
pub type ScopedSupercow<'a, OWNED, BORROWED = OWNED, SHARED = Box<DefaultFeatures<'a> + 'a>> =
Supercow<'a, OWNED, BORROWED, SHARED, BoxedStorage>;
-
-
-
-