aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread.rs
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-11-05 08:15:27 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-11-05 08:15:27 +0100
commit942740b143c8f07f402da8e20338c8f769fe5447 (patch)
tree738254b10ded304175c8e5b94f25c28caca303aa /src/thread.rs
parent228e7665bc4dc20929ea2a8cb52600da3d4dd839 (diff)
downloadmail-942740b143c8f07f402da8e20338c8f769fe5447.tar.gz
implement 'Ext' traits for all types exept iterators
Diffstat (limited to 'src/thread.rs')
-rw-r--r--src/thread.rs46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/thread.rs b/src/thread.rs
index 36da638..e9ecdad 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -1,5 +1,5 @@
use std::ops::Drop;
-use supercow::Phantomcow;
+use supercow::{Supercow, Phantomcow};
use ffi;
use utils::ToStr;
@@ -56,26 +56,17 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> {
}
pub fn toplevel_messages(self: &Self) -> Messages<Self> {
- Messages::from_ptr(
- unsafe { ffi::notmuch_thread_get_toplevel_messages(self.handle.ptr) },
- self,
- )
+ <Self as ThreadExt<'o, Owner>>::toplevel_messages(self)
}
/// Get a `Messages` iterator for all messages in 'thread' in
/// oldest-first order.
pub fn messages(self: &Self) -> Messages<Self> {
- Messages::from_ptr(
- unsafe { ffi::notmuch_thread_get_messages(self.handle.ptr) },
- self,
- )
+ <Self as ThreadExt<'o, Owner>>::messages(self)
}
pub fn tags(&self) -> Tags<Self> {
- Tags::from_ptr(
- unsafe { ffi::notmuch_thread_get_tags(self.handle.ptr) },
- self,
- )
+ <Self as ThreadExt<'o, Owner>>::tags(self)
}
pub fn subject(self: &Self) -> String {
@@ -107,7 +98,36 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> {
}
pub trait ThreadExt<'o, Owner: ThreadOwner + 'o>{
+ fn tags<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>(thread: S) -> Tags<'s, Thread<'o, Owner>> {
+ let threadref = thread.into();
+ Tags::from_ptr(
+ unsafe { ffi::notmuch_thread_get_tags(threadref.handle.ptr) },
+ Supercow::phantom(threadref)
+ )
+ }
+
+ fn toplevel_messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>(thread: S) -> Messages<'s, Thread<'o, Owner>> {
+ let threadref = thread.into();
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) },
+ Supercow::phantom(threadref)
+ )
+ }
+
+ /// Get a `Messages` iterator for all messages in 'thread' in
+ /// oldest-first order.
+ fn messages<'s, S: Into<Supercow<'s, Thread<'o, Owner>>>>(thread: S) -> Messages<'s, Thread<'o, Owner>> {
+ let threadref = thread.into();
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) },
+ Supercow::phantom(threadref)
+ )
+ }
+
+}
+impl<'o, Owner: ThreadOwner + 'o> ThreadExt<'o, Owner> for Thread<'o, Owner>{
+
}
unsafe impl<'o, Owner: ThreadOwner + 'o> Send for Thread<'o, Owner> {}