From d4d8969c83077b409137a32c11e6b18b6ca2fdff Mon Sep 17 00:00:00 2001 From: eaon Date: Mon, 19 Nov 2018 17:21:58 -0500 Subject: Add Database::remove_message --- src/database.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/database.rs b/src/database.rs index d5e6700..8f365cb 100644 --- a/src/database.rs +++ b/src/database.rs @@ -9,6 +9,7 @@ use libc; use error::Result; use ffi; +use ffi::Status; use query::QueryPtr; use utils::ToStr; use Directory; @@ -140,8 +141,7 @@ impl Database { }, status.map_or(ptr::null_mut(), |f| &f as *const _ as *mut libc::c_void), ) - } - .as_result() + }.as_result() ); Ok(()) @@ -220,8 +220,7 @@ impl Database { }, status.map_or(ptr::null_mut(), |f| &f as *const _ as *mut libc::c_void), ) - } - .as_result() + }.as_result() ); Ok(()) @@ -241,6 +240,13 @@ impl Database { pub fn all_tags<'d>(&'d self) -> Result> { ::all_tags(self) } + + pub fn remove_message<'d, P>(&'d self, path: &P) -> Status + where + P: AsRef, + { + ::remove_message(self, path) + } } pub trait DatabaseExt { @@ -280,8 +286,7 @@ pub trait DatabaseExt { try!( unsafe { ffi::notmuch_database_get_directory(dbref.handle.ptr, path_str.as_ptr(), &mut dir) - } - .as_result() + }.as_result() ); if dir.is_null() { @@ -290,6 +295,19 @@ pub trait DatabaseExt { Ok(Some(Directory::from_ptr(dir, Supercow::phantom(dbref)))) } } + + fn remove_message<'d, D, P>(database: D, path: &P) -> Status + where + D: Into>, + P: AsRef, + { + let dbref = database.into(); + let msg_path = CString::new(path.as_ref()).unwrap(); + + Status::from(unsafe { + ffi::notmuch_database_remove_message(dbref.handle.ptr, msg_path.as_ptr()) + }) + } } impl DatabaseExt for Database {} -- cgit v1.2.1