From 361e1a8f12590c49b969fc4c01ede1454ec69776 Mon Sep 17 00:00:00 2001 From: eaon Date: Fri, 2 Nov 2018 18:02:37 -0400 Subject: Add Message::{date,add_tag,remove_tag,remove_all_tags} and make clippy usable (#6) * Removing unnecessary lifetimes and borrows * Add Message::{date,add_tag,remove_tag,remove_all_tags} * Make sure clippy doesn't error out --- src/ffi.rs | 6 +++--- src/message.rs | 34 +++++++++++++++++++++++++++++++--- src/thread.rs | 2 +- 3 files changed, 35 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ffi.rs b/src/ffi.rs index 3c281fa..373dc53 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -47,14 +47,14 @@ notmuch_enum! { } impl notmuch_status_t { - pub fn is_ok(&self) -> bool { - match *self { + pub fn is_ok(self) -> bool { + match self { notmuch_status_t::NOTMUCH_STATUS_SUCCESS => true, _ => false, } } - pub fn is_err(&self) -> bool { + pub fn is_err(self) -> bool { !self.is_ok() } diff --git a/src/message.rs b/src/message.rs index 624817d..ed72997 100644 --- a/src/message.rs +++ b/src/message.rs @@ -5,6 +5,7 @@ use supercow::Phantomcow; use error::{Error, Result}; use ffi; +use ffi::Status; use utils::ToStr; use Filenames; use FilenamesOwner; @@ -57,7 +58,7 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { tid.to_str().unwrap().to_string() } - pub fn replies<'s>(self: &'s Self) -> Messages<'s, Self> { + pub fn replies(self: &Self) -> Messages { Messages::from_ptr( unsafe { ffi::notmuch_message_get_replies(self.handle.ptr) }, self, @@ -84,9 +85,16 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { ) } + pub fn date(&self) -> i64 { + unsafe { + ffi::notmuch_message_get_date(self.handle.ptr) + } + } + pub fn header(&self, name: &str) -> Result<&str> { + let name = CString::new(name).unwrap(); let ret = unsafe { - ffi::notmuch_message_get_header(self.handle.ptr, CString::new(name).unwrap().as_ptr()) + ffi::notmuch_message_get_header(self.handle.ptr, name.as_ptr()) }; if ret.is_null() { Err(Error::UnspecifiedError) @@ -95,12 +103,32 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } } - pub fn tags<'m>(&'m self) -> Tags<'m, Self> { + pub fn tags(&self) -> Tags { Tags::from_ptr( unsafe { ffi::notmuch_message_get_tags(self.handle.ptr) }, self, ) } + + pub fn add_tag(self: &Self, tag: &str) -> Status { + let tag = CString::new(tag).unwrap(); + Status::from(unsafe { + ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) + }) + } + + pub fn remove_tag(self: &Self, tag: &str) -> Status { + let tag = CString::new(tag).unwrap(); + Status::from(unsafe { + ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) + }) + } + + pub fn remove_all_tags(self: &Self) -> Status { + Status::from(unsafe { + ffi::notmuch_message_remove_all_tags(self.handle.ptr) + }) + } } unsafe impl<'o, Owner: MessageOwner + 'o> Send for Message<'o, Owner> {} diff --git a/src/thread.rs b/src/thread.rs index 9a63c94..c112e06 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -71,7 +71,7 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> { ) } - pub fn tags<'t>(&'t self) -> Tags<'t, Self> { + pub fn tags(&self) -> Tags { Tags::from_ptr( unsafe { ffi::notmuch_thread_get_tags(self.handle.ptr) }, self, -- cgit v1.2.1