aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-17 18:29:55 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-17 18:29:55 +0100
commitd74e6fee5dc34e8015f4d9699b5624d7a60a3c8a (patch)
treefefa2c6d2c312385986364eddcab9a02f53d966a
parent0d510d55c4238ff0a1175985b27ca38c71a3cfc2 (diff)
downloadmail-d74e6fee5dc34e8015f4d9699b5624d7a60a3c8a.tar.gz
Revert "link lifetime of message to Query"
This reverts commit 0d510d55c4238ff0a1175985b27ca38c71a3cfc2.
-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, 88 insertions, 96 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7948f77..ef8cc33 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};
+pub use ffi::{DatabaseMode, Sort}; \ No newline at end of file
diff --git a/src/message.rs b/src/message.rs
index 80e7c46..8cc7af2 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -10,7 +10,6 @@ use FilenamesOwner;
use Messages;
use Tags;
use TagsOwner;
-use Query;
pub trait MessageOwner: Send + Sync {}
@@ -20,25 +19,25 @@ pub(crate) struct MessagePtr {
}
#[derive(Debug)]
-pub struct Message<'d, 'q>
+pub struct Message<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
pub(crate) handle: MessagePtr,
- marker: ScopedPhantomcow<'q, Query<'d>>,
+ marker: ScopedPhantomcow<'o, 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> 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> Message<'d, 'q>
+impl<'o, O> Message<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
- pub fn from_ptr<P>(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'d, 'q>
+ pub fn from_ptr<P>(ptr: *mut ffi::notmuch_message_t, owner: P) -> Message<'o, O>
where
- P: Into<ScopedPhantomcow<'q, Query<'d>>>,
+ P: Into<ScopedPhantomcow<'o, O>>,
{
Message {
handle: MessagePtr { ptr },
@@ -56,12 +55,8 @@ where
tid.to_str().unwrap().to_string()
}
- 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),
- )
+ pub fn replies(self: &Self) -> Messages<Self> {
+ <Self as MessageExt<'o, O>>::replies(self)
}
#[cfg(feature = "v0_26")]
@@ -70,7 +65,7 @@ where
}
pub fn filenames(self: &Self) -> Filenames<Self> {
- <Self as MessageExt<'d, 'q>>::filenames(self)
+ <Self as MessageExt<'o, O>>::filenames(self)
}
pub fn filename(self: &Self) -> PathBuf {
@@ -99,7 +94,7 @@ where
}
pub fn tags(&self) -> Tags<Self> {
- <Self as MessageExt<'d, 'q>>::tags(self)
+ <Self as MessageExt<'o, O>>::tags(self)
}
pub fn add_tag(self: &Self, tag: &str) -> Result<()> {
@@ -117,13 +112,13 @@ where
}
}
-pub trait MessageExt<'d, 'q>
+pub trait MessageExt<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
- fn tags<'s, S>(message: S) -> Tags<'s, Message<'d, 'q>>
+ fn tags<'s, S>(message: S) -> Tags<'s, Message<'o, O>>
where
- S: Into<ScopedSupercow<'s, Message<'d, 'q>>>,
+ S: Into<ScopedSupercow<'s, Message<'o, O>>>,
{
let messageref = message.into();
Tags::from_ptr(
@@ -132,20 +127,20 @@ where
)
}
- // 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 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 filenames<'s, S>(message: S) -> Filenames<'s, Message<'d, 'q>>
+ fn filenames<'s, S>(message: S) -> Filenames<'s, Message<'o, O>>
where
- S: Into<ScopedSupercow<'s, Message<'d, 'q>>>,
+ S: Into<ScopedSupercow<'s, Message<'o, O>>>,
{
let messageref = message.into();
Filenames::from_ptr(
@@ -155,7 +150,7 @@ where
}
}
-impl<'d, 'q> MessageExt<'d, 'q> for Message<'d, 'q> where 'd: 'q {}
+impl<'o, O> MessageExt<'o, O> 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 {}
+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 {}
diff --git a/src/messages.rs b/src/messages.rs
index 2401293..db92f73 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -6,7 +6,6 @@ use MessageOwner;
use Message;
use Tags;
use TagsOwner;
-use Query;
#[derive(Debug)]
pub struct MessagesPtr {
@@ -20,21 +19,21 @@ impl Drop for MessagesPtr {
}
#[derive(Debug)]
-pub struct Messages<'d, 'q>
+pub struct Messages<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
pub(crate) handle: MessagesPtr,
- marker: ScopedPhantomcow<'q, Query<'d>>,
+ marker: ScopedPhantomcow<'o, O>,
}
-impl<'d, 'q> Messages<'d, 'q>
+impl<'o, O> Messages<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
- pub(crate) fn from_ptr<P>(ptr: *mut ffi::notmuch_messages_t, owner: P) -> Messages<'d, 'q>
+ pub(crate) fn from_ptr<P>(ptr: *mut ffi::notmuch_messages_t, owner: P) -> Messages<'o, O>
where
- P: Into<ScopedPhantomcow<'q, Query<'d>>>,
+ P: Into<ScopedPhantomcow<'o, O>>,
{
Messages {
handle: MessagesPtr { ptr },
@@ -43,12 +42,12 @@ where
}
}
-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> MessageOwner for Messages<'o, O> where O: MessageOwner + 'o {}
+impl<'o, O> TagsOwner for Messages<'o, O> where O: MessageOwner + 'o {}
-impl<'d, 'q> Messages<'d, 'q>
+impl<'o, O> Messages<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
/**
* Return a list of tags from all messages.
@@ -63,7 +62,7 @@ where
*
* The function returns NULL on error.
*/
- pub fn collect_tags<'m>(self: &'m Self) -> Tags<'m, Self> {
+ pub fn collect_tags<'m>(self: &'o Self) -> Tags<'m, Self> {
Tags::from_ptr(
unsafe { ffi::notmuch_messages_collect_tags(self.handle.ptr) },
self,
@@ -71,11 +70,11 @@ where
}
}
-impl<'d, 'q> Iterator for Messages<'d, 'q>
+impl<'o, O> Iterator for Messages<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
- type Item = Message<'d, 'q>;
+ type Item = Message<'o, O>;
fn next(&mut self) -> Option<Self::Item> {
let valid = unsafe { ffi::notmuch_messages_valid(self.handle.ptr) };
@@ -90,20 +89,20 @@ where
thrd
};
- Some(Message::from_ptr(cthrd, ScopedPhantomcow::<'q, Query<'d>>::share(&mut self.marker)))
+ Some(Message::from_ptr(cthrd, ScopedPhantomcow::<'o, O>::share(&mut self.marker)))
}
}
-pub trait MessagesExt<'d, 'q>
+pub trait MessagesExt<'o, O>
where
- 'd: 'q,
+ O: MessageOwner + 'o,
{
}
-impl<'d, 'q> MessagesExt<'q, 'q> for Messages<'d, 'q> where 'd: 'q {}
+impl<'o, O> MessagesExt<'o, O> 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 {}
+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 97a3f52..adbed58 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<'d, 'q>> {
+ pub fn search_messages<'q>(self: &'d Self) -> Result<Messages<'q, Self>> {
<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<'d, 'q>>
+ fn search_messages<'q, Q>(query: Q) -> Result<Messages<'q, Query<'d>>>
where
Q: Into<ScopedSupercow<'q, Query<'d>>>,
{
diff --git a/src/thread.rs b/src/thread.rs
index 20280e1..137c936 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -59,20 +59,14 @@ where
unsafe { ffi::notmuch_thread_get_total_files(self.handle.ptr) }
}
- 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),
- )
+ pub fn toplevel_messages(self: &Self) -> 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: &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 messages(self: &Self) -> Messages<'_, Self> {
+ <Self as ThreadExt<'d, 'q>>::messages(self)
}
pub fn tags(&self) -> Tags<'_, Self> {
@@ -122,29 +116,29 @@ where
)
}
- // 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),
- // )
- // }
+ 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),
+ )
+ }
}
impl<'d, 'q> ThreadExt<'d, 'q> for Thread<'d, 'q> where 'd: 'q {}
diff --git a/src/utils.rs b/src/utils.rs
index ab21d13..409534c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -37,3 +37,7 @@ 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>;
+
+
+
+