aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread.rs
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-11-01 21:55:00 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-11-01 21:55:00 +0100
commit7d2be237297c16628cb3d58774e808cac9c92fc1 (patch)
tree55cb240828bac9968f94166e740b567b66928e3b /src/thread.rs
parent2932d67d87fa2ff41fcdf46ce269ba5b49294930 (diff)
downloadmail-7d2be237297c16628cb3d58774e808cac9c92fc1.tar.gz
improve lifetime management with supercow
Diffstat (limited to 'src/thread.rs')
-rw-r--r--src/thread.rs126
1 files changed, 54 insertions, 72 deletions
diff --git a/src/thread.rs b/src/thread.rs
index 55ed982..9a63c94 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -1,128 +1,110 @@
use std::ops::Drop;
-use std::marker::PhantomData;
+use supercow::Phantomcow;
+
use ffi;
-use utils::{
- FromPtr,
- ToStr
-};
-use Query;
+use utils::ToStr;
use Messages;
+use MessagesOwner;
use Tags;
-use messages::MessagesOwner;
-use tags::TagsOwner;
-
-pub trait ThreadOwner{}
+use TagsOwner;
+pub trait ThreadOwner {}
#[derive(Debug)]
pub(crate) struct ThreadPtr {
- pub ptr: *mut ffi::notmuch_thread_t
+ pub ptr: *mut ffi::notmuch_thread_t,
}
impl Drop for ThreadPtr {
fn drop(&mut self) {
- unsafe {
- ffi::notmuch_thread_destroy(self.ptr)
- };
+ unsafe { ffi::notmuch_thread_destroy(self.ptr) };
}
}
-
#[derive(Debug)]
-pub struct Thread<'o, Owner: ThreadOwner + 'o>{
+pub struct Thread<'o, Owner: ThreadOwner + 'o> {
pub(crate) handle: ThreadPtr,
- phantom: PhantomData<&'o Owner>,
+ marker: Phantomcow<'o, Owner>,
}
-impl<'o, Owner: ThreadOwner + 'o> MessagesOwner for Thread<'o, Owner>{}
-impl<'o, Owner: ThreadOwner + 'o> TagsOwner for Thread<'o, Owner>{}
-
-
-impl<'o, Owner: ThreadOwner + 'o> FromPtr<*mut ffi::notmuch_thread_t> for Thread<'o, Owner> {
- fn from_ptr(ptr: *mut ffi::notmuch_thread_t) -> Thread<'o, Owner> {
- Thread{
- handle: ThreadPtr{ptr},
- phantom: PhantomData
+impl<'o, Owner: ThreadOwner + 'o> MessagesOwner for Thread<'o, Owner> {}
+impl<'o, Owner: ThreadOwner + 'o> TagsOwner for Thread<'o, Owner> {}
+
+impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> {
+ pub fn from_ptr<O: Into<Phantomcow<'o, Owner>>>(
+ ptr: *mut ffi::notmuch_thread_t,
+ owner: O,
+ ) -> Thread<'o, Owner> {
+ Thread {
+ handle: ThreadPtr { ptr },
+ marker: owner.into(),
}
}
-}
-
-impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner>{
- pub fn id(self: &Self) -> String{
- let tid = unsafe {
- ffi::notmuch_thread_get_thread_id(self.handle.ptr)
- };
+ pub fn id(self: &Self) -> String {
+ let tid = unsafe { ffi::notmuch_thread_get_thread_id(self.handle.ptr) };
tid.to_str().unwrap().to_string()
}
-
- pub fn total_messages(self: &Self) -> i32{
- unsafe {
- ffi::notmuch_thread_get_total_messages(self.handle.ptr)
- }
+ pub fn total_messages(self: &Self) -> i32 {
+ unsafe { ffi::notmuch_thread_get_total_messages(self.handle.ptr) }
}
#[cfg(feature = "0.26")]
- pub fn total_files(self: &Self) -> i32{
- unsafe {
- ffi::notmuch_thread_get_total_files(self.handle.ptr)
- }
+ pub fn total_files(self: &Self) -> i32 {
+ unsafe { ffi::notmuch_thread_get_total_files(self.handle.ptr) }
}
-
- pub fn toplevel_messages(self: &Self) -> Messages<Self>{
- Messages::from_ptr(unsafe {
- ffi::notmuch_thread_get_toplevel_messages(self.handle.ptr)
- })
+ pub fn toplevel_messages(self: &Self) -> Messages<Self> {
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_thread_get_toplevel_messages(self.handle.ptr) },
+ 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)
- })
+ pub fn messages(self: &Self) -> Messages<Self> {
+ Messages::from_ptr(
+ unsafe { ffi::notmuch_thread_get_messages(self.handle.ptr) },
+ self,
+ )
}
-
- pub fn tags<'t>(self: &Self) -> Tags<'t, Self>{
- Tags::from_ptr(unsafe {
- ffi::notmuch_thread_get_tags(self.handle.ptr)
- })
+ pub fn tags<'t>(&'t self) -> Tags<'t, Self> {
+ Tags::from_ptr(
+ unsafe { ffi::notmuch_thread_get_tags(self.handle.ptr) },
+ self,
+ )
}
- pub fn subject(self: &Self) -> String{
- let sub = unsafe {
- ffi::notmuch_thread_get_subject(self.handle.ptr)
- };
+ pub fn subject(self: &Self) -> String {
+ let sub = unsafe { ffi::notmuch_thread_get_subject(self.handle.ptr) };
sub.to_str().unwrap().to_string()
}
- pub fn authors(self: &Self) -> Vec<String>{
- let athrs = unsafe {
- ffi::notmuch_thread_get_authors(self.handle.ptr)
- };
+ pub fn authors(self: &Self) -> Vec<String> {
+ let athrs = unsafe { ffi::notmuch_thread_get_authors(self.handle.ptr) };
- athrs.to_str().unwrap().split(',').map(|s| s.to_string()).collect()
+ athrs
+ .to_str()
+ .unwrap()
+ .split(',')
+ .map(|s| s.to_string())
+ .collect()
}
/// Get the date of the oldest message in 'thread' as a time_t value.
pub fn oldest_date(self: &Self) -> i64 {
- unsafe {
- ffi::notmuch_thread_get_oldest_date(self.handle.ptr)
- }
+ unsafe { ffi::notmuch_thread_get_oldest_date(self.handle.ptr) }
}
/// Get the date of the newest message in 'thread' as a time_t value.
pub fn newest_date(self: &Self) -> i64 {
- unsafe {
- ffi::notmuch_thread_get_newest_date(self.handle.ptr)
- }
+ unsafe { ffi::notmuch_thread_get_newest_date(self.handle.ptr) }
}
}
-
unsafe impl<'o, Owner: ThreadOwner + 'o> Send for Thread<'o, Owner> {}
unsafe impl<'o, Owner: ThreadOwner + 'o> Sync for Thread<'o, Owner> {}