From 8e76db5f75c9c315236bc6f8c6e195cec6103537 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Fri, 23 Mar 2018 07:01:03 +0100 Subject: count threads and messages --- src/ffi.rs | 8 +++++--- src/query.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index caecc0e..58965cc 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -856,7 +856,8 @@ extern { /// @since libnotmuch 4.3 (notmuch 0.21) pub fn notmuch_query_count_messages( query: *mut notmuch_query_t, - ) -> c_uint; + count: *mut c_uint + ) -> notmuch_status_t; /// Return the number of threads matching a search. @@ -879,9 +880,10 @@ extern { /// value of *count is not defined. /// /// @since libnotmuch 4.3 (notmuch 0.21) - pub fn notmuch_count_threads( + pub fn notmuch_query_count_threads( query: *mut notmuch_query_t, - ) -> c_uint; + count: *mut c_uint + ) -> notmuch_status_t; /// Get the thread ID of 'thread'. /// diff --git a/src/query.rs b/src/query.rs index 68e9baf..2873b27 100644 --- a/src/query.rs +++ b/src/query.rs @@ -66,6 +66,21 @@ impl<'d> Query<'d> { } } + pub fn count_messages(self: &Self) -> Result + { + let mut cnt = 0; + let ret = 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(); @@ -80,6 +95,21 @@ impl<'d> Query<'d> { true => Ok(Some(Threads::new(thrds))), } } + + pub fn count_threads(self: &Self) -> Result + { + let mut cnt = 0; + let ret = try!(unsafe { + ffi::notmuch_query_count_threads( + self.0, &mut cnt, + ) + }.as_result()); + + // if ret.is_err(){ + // return ret; + // } + return Ok(cnt); + } } impl<'d> NewFromPtr<*mut ffi::notmuch_query_t> for Query<'d> { -- cgit v1.2.1