diff options
| author | eaon <eaon@mit.edu> | 2018-11-21 20:06:21 +0100 |
|---|---|---|
| committer | eaon <eaon@mit.edu> | 2018-11-21 20:06:21 +0100 |
| commit | 4ca963a68258abed7f158ffa5289030026e11720 (patch) | |
| tree | c36707e83bc8ec8fc8e129b9acda006b2c46e97f | |
| parent | 121856a6ef3be6a8a353f381dc319580efa8d86a (diff) | |
| download | mail-4ca963a68258abed7f158ffa5289030026e11720.tar.gz | |
Return Result<(), Status::NotmuchError> instead of Status
| -rw-r--r-- | src/database.rs | 13 | ||||
| -rw-r--r-- | src/ffi.rs | 7 | ||||
| -rw-r--r-- | src/message.rs | 13 |
3 files changed, 16 insertions, 17 deletions
diff --git a/src/database.rs b/src/database.rs index 5ed9537..102a7a9 100644 --- a/src/database.rs +++ b/src/database.rs @@ -7,7 +7,7 @@ use supercow::Supercow; use libc; -use error::Result; +use error::{Error, Result}; use ffi; use ffi::Status; use query::QueryPtr; @@ -235,7 +235,7 @@ impl Database { <Self as DatabaseExt>::all_tags(self) } - pub fn remove_message<'d, P>(&'d self, path: &P) -> Status + pub fn remove_message<'d, P>(&'d self, path: &P) -> Result<()> where P: AsRef<Path>, { @@ -288,7 +288,7 @@ pub trait DatabaseExt { } } - fn remove_message<'d, D, P>(database: D, path: &P) -> Status + fn remove_message<'d, D, P>(database: D, path: &P) -> Result<()> where D: Into<Supercow<'d, Database>>, P: AsRef<Path>, @@ -298,11 +298,10 @@ pub trait DatabaseExt { Some(path_str) => { let msg_path = CString::new(path_str).unwrap(); - Status::from(unsafe { - ffi::notmuch_database_remove_message(dbref.handle.ptr, msg_path.as_ptr()) - }) + unsafe { ffi::notmuch_database_remove_message(dbref.handle.ptr, msg_path.as_ptr()) } + .as_result() } - None => Status::FileError, + None => Err(Error::NotmuchError(Status::FileError)), } } } @@ -4,6 +4,7 @@ use libc::{c_char, c_double, c_int, c_uint, c_ulong, c_void, time_t}; +use error::{Error, Result}; use std::{error, fmt, str}; use utils::ToStr; @@ -43,17 +44,17 @@ impl notmuch_status_t { !self.is_ok() } - pub fn as_result(self) -> Result<(), Self> { + pub fn as_result(self) -> Result<()> { if self.is_ok() { Ok(()) } else { - Err(self) + Err(Error::NotmuchError(Status::from(self))) } } } impl ToStr for Status { - fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> { + fn to_str<'a>(&self) -> std::result::Result<&'a str, str::Utf8Error> { unsafe { notmuch_status_to_string((*self).into()) }.to_str() } } diff --git a/src/message.rs b/src/message.rs index 83a834f..6feffde 100644 --- a/src/message.rs +++ b/src/message.rs @@ -5,7 +5,6 @@ use supercow::{Phantomcow, Supercow}; use error::{Error, Result}; use ffi; -use ffi::Status; use utils::ToStr; use Filenames; use FilenamesOwner; @@ -106,18 +105,18 @@ where <Self as MessageExt<'o, O>>::tags(self) } - pub fn add_tag(self: &Self, tag: &str) -> Status { + pub fn add_tag(self: &Self, tag: &str) -> Result<()> { let tag = CString::new(tag).unwrap(); - Status::from(unsafe { ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) }) + unsafe { ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) }.as_result() } - pub fn remove_tag(self: &Self, tag: &str) -> Status { + pub fn remove_tag(self: &Self, tag: &str) -> Result<()> { let tag = CString::new(tag).unwrap(); - Status::from(unsafe { ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) }) + unsafe { ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) }.as_result() } - pub fn remove_all_tags(self: &Self) -> Status { - Status::from(unsafe { ffi::notmuch_message_remove_all_tags(self.handle.ptr) }) + pub fn remove_all_tags(self: &Self) -> Result<()> { + unsafe { ffi::notmuch_message_remove_all_tags(self.handle.ptr) }.as_result() } } |
