From 188068f051976f8dd4bf1b0da5fcb4bc2c6ae185 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Fri, 23 Mar 2018 07:50:00 +0100 Subject: cleanup --- Cargo.toml | 5 ++--- src/database.rs | 12 +++--------- src/query.rs | 14 ++++---------- src/thread.rs | 13 ++++++++++++- src/utils.rs | 12 ++++++++++++ 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4145e46..cec9c63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,7 @@ [package] name = "notmuch" -version = "0.0.4" -authors = ["C. Morgan Hamill ", - "Dirk Van Haerenborgh "] +version = "0.0.5" +authors = ["Dirk Van Haerenborgh "] homepage = "https://github.com/vhdirk/notmuch-rs" repository = "https://github.com/vhdirk/notmuch-rs" diff --git a/src/database.rs b/src/database.rs index b0e8b75..121a87c 100644 --- a/src/database.rs +++ b/src/database.rs @@ -62,9 +62,7 @@ impl Database { pub fn close(self) -> Result<()> { try!(unsafe { ffi::notmuch_database_close(self.0) - }.as_result()); - - Ok(()) + }.as_result()) } pub fn compact, F: FnMut(&str)>( @@ -107,9 +105,7 @@ impl Database { &f as *const _ as *mut libc::c_void }), ) - }.as_result()); - - Ok(()) + }.as_result()) } pub fn path(&self) -> &path::Path { @@ -166,9 +162,7 @@ impl Database { &f as *const _ as *mut libc::c_void }), ) - }.as_result()); - - Ok(()) + }.as_result()) } pub fn directory>(&self, path: &P) -> Result> { diff --git a/src/query.rs b/src/query.rs index 2873b27..36e9be6 100644 --- a/src/query.rs +++ b/src/query.rs @@ -54,7 +54,7 @@ impl<'d> Query<'d> { pub fn search_messages(self: &Self) -> Result> { let mut msgs = ptr::null_mut(); - let ret = try!(unsafe { + try!(unsafe { ffi::notmuch_query_search_messages( self.0, &mut msgs, ) @@ -69,22 +69,19 @@ impl<'d> Query<'d> { pub fn count_messages(self: &Self) -> Result { let mut cnt = 0; - let ret = try!(unsafe { + try!(unsafe { ffi::notmuch_query_count_messages( self.0, &mut cnt, ) }.as_result()); - // if ret.is_err(){ - // return ret; - // } return Ok(cnt); } pub fn search_threads(self: &Self) -> Result> { let mut thrds = ptr::null_mut(); - let ret = try!(unsafe { + try!(unsafe { ffi::notmuch_query_search_threads( self.0, &mut thrds, ) @@ -99,15 +96,12 @@ impl<'d> Query<'d> { pub fn count_threads(self: &Self) -> Result { let mut cnt = 0; - let ret = try!(unsafe { + try!(unsafe { ffi::notmuch_query_count_threads( self.0, &mut cnt, ) }.as_result()); - // if ret.is_err(){ - // return ret; - // } return Ok(cnt); } } diff --git a/src/thread.rs b/src/thread.rs index 2a502b4..2743f0a 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -2,14 +2,17 @@ use std; use std::{ ops, marker, - ptr, + str, + result }; +use std::ffi::{CString, CStr}; use error::Result; use ffi; use utils::{ NewFromPtr, + ToStr }; use Query; @@ -27,6 +30,14 @@ impl<'q, 'd> NewFromPtr<*mut ffi::notmuch_thread_t> for Thread<'q, 'd> { impl<'q, 'd> Thread<'q, 'd>{ + pub fn id(self: &Self) -> result::Result<&'q str, str::Utf8Error>{ + let tid = unsafe { + ffi::notmuch_thread_get_thread_id(self.0) + }; + tid.to_str() + } + + pub fn total_messages(self: &Self) -> i32{ unsafe { ffi::notmuch_thread_get_total_messages(self.0) diff --git a/src/utils.rs b/src/utils.rs index fa24029..e1f691c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -20,3 +20,15 @@ impl ToStr for *const libc::c_char { }.to_bytes()) } } + +pub trait ToString { + fn to_string(&self) -> String; +} + +impl ToString for *const libc::c_char { + fn to_string(&self) -> String { + unsafe { + ffi::CStr::from_ptr(*self).to_string_lossy().into_owned() + } + } +} -- cgit v1.2.1