aboutsummaryrefslogtreecommitdiffstats
path: root/src/message.rs
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-20 08:21:03 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-20 08:21:03 +0100
commitbb8a60ddc9fdecc6c1004639514b538578e37532 (patch)
tree634968cabab56edec2f8a750903c155800a0f031 /src/message.rs
parent2baa9d13ad4c5c2c6e55b6ca49c92a4d2434fba7 (diff)
downloadmail-bb8a60ddc9fdecc6c1004639514b538578e37532.tar.gz
remove ptr indirection
Diffstat (limited to 'src/message.rs')
-rw-r--r--src/message.rs35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/message.rs b/src/message.rs
index b2b466f..226d3b8 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -15,16 +15,11 @@ use TagsOwner;
pub trait MessageOwner: Send + Sync {}
#[derive(Debug)]
-pub(crate) struct MessagePtr {
- pub ptr: *mut ffi::notmuch_message_t,
-}
-
-#[derive(Debug)]
pub struct Message<'o, O>
where
O: MessageOwner + 'o,
{
- pub(crate) handle: MessagePtr,
+ pub(crate) ptr: *mut ffi::notmuch_message_t,
marker: RefCell<ScopedPhantomcow<'o, O>>,
}
@@ -41,24 +36,24 @@ where
P: Into<ScopedPhantomcow<'o, O>>,
{
Message {
- handle: MessagePtr { ptr },
+ ptr,
marker: RefCell::new(owner.into()),
}
}
pub fn id(self: &Self) -> String {
- let mid = unsafe { ffi::notmuch_message_get_message_id(self.handle.ptr) };
+ let mid = unsafe { ffi::notmuch_message_get_message_id(self.ptr) };
mid.to_str().unwrap().to_string()
}
pub fn thread_id(self: &Self) -> String {
- let tid = unsafe { ffi::notmuch_message_get_thread_id(self.handle.ptr) };
+ let tid = unsafe { ffi::notmuch_message_get_thread_id(self.ptr) };
tid.to_str().unwrap().to_string()
}
pub fn replies(self: &Self) -> Messages<'o, O> {
Messages::<'o, O>::from_ptr(
- unsafe { ffi::notmuch_message_get_replies(self.handle.ptr) },
+ unsafe { ffi::notmuch_message_get_replies(self.ptr) },
// will never panic since the borrow is released immediately
ScopedPhantomcow::<'o, O>::share(&mut *(self.marker.borrow_mut()))
)
@@ -66,7 +61,7 @@ where
#[cfg(feature = "v0_26")]
pub fn count_files(self: &Self) -> i32 {
- unsafe { ffi::notmuch_message_count_files(self.handle.ptr) }
+ unsafe { ffi::notmuch_message_count_files(self.ptr) }
}
pub fn filenames(self: &Self) -> Filenames<Self> {
@@ -75,19 +70,19 @@ where
pub fn filename(self: &Self) -> PathBuf {
PathBuf::from(
- unsafe { ffi::notmuch_message_get_filename(self.handle.ptr) }
+ unsafe { ffi::notmuch_message_get_filename(self.ptr) }
.to_str()
.unwrap(),
)
}
pub fn date(&self) -> i64 {
- unsafe { ffi::notmuch_message_get_date(self.handle.ptr) as i64 }
+ unsafe { ffi::notmuch_message_get_date(self.ptr) as i64 }
}
pub fn header(&self, name: &str) -> Result<Option<&str>> {
let name = CString::new(name).unwrap();
- let ret = unsafe { ffi::notmuch_message_get_header(self.handle.ptr, name.as_ptr()) };
+ let ret = unsafe { ffi::notmuch_message_get_header(self.ptr, name.as_ptr()) };
if ret.is_null() {
Err(Error::UnspecifiedError)
} else {
@@ -104,16 +99,16 @@ where
pub fn add_tag(self: &Self, tag: &str) -> Result<()> {
let tag = CString::new(tag).unwrap();
- unsafe { ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) }.as_result()
+ unsafe { ffi::notmuch_message_add_tag(self.ptr, tag.as_ptr()) }.as_result()
}
pub fn remove_tag(self: &Self, tag: &str) -> Result<()> {
let tag = CString::new(tag).unwrap();
- unsafe { ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) }.as_result()
+ unsafe { ffi::notmuch_message_remove_tag(self.ptr, tag.as_ptr()) }.as_result()
}
pub fn remove_all_tags(self: &Self) -> Result<()> {
- unsafe { ffi::notmuch_message_remove_all_tags(self.handle.ptr) }.as_result()
+ unsafe { ffi::notmuch_message_remove_all_tags(self.ptr) }.as_result()
}
}
@@ -127,7 +122,7 @@ where
{
let messageref = message.into();
Tags::from_ptr(
- unsafe { ffi::notmuch_message_get_tags(messageref.handle.ptr) },
+ unsafe { ffi::notmuch_message_get_tags(messageref.ptr) },
Supercow::phantom(messageref),
)
}
@@ -138,7 +133,7 @@ where
// {
// let messageref = message.into();
// Messages::from_ptr(
- // unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) },
+ // unsafe { ffi::notmuch_message_get_replies(messageref.ptr) },
// Supercow::phantom(messageref),
// )
// }
@@ -149,7 +144,7 @@ where
{
let messageref = message.into();
Filenames::from_ptr(
- unsafe { ffi::notmuch_message_get_filenames(messageref.handle.ptr) },
+ unsafe { ffi::notmuch_message_get_filenames(messageref.ptr) },
Supercow::phantom(messageref),
)
}