aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-03-23 07:50:00 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-03-23 07:50:00 +0100
commit188068f051976f8dd4bf1b0da5fcb4bc2c6ae185 (patch)
tree339a0eb7b9d72d8f716e153a77c1052be0b5f58d
parentba417206ed8bb2341dcad5655d91ad09f6a0f073 (diff)
downloadmail-188068f051976f8dd4bf1b0da5fcb4bc2c6ae185.tar.gz
cleanup
-rw-r--r--Cargo.toml5
-rw-r--r--src/database.rs12
-rw-r--r--src/query.rs14
-rw-r--r--src/thread.rs13
-rw-r--r--src/utils.rs12
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 <me@cmhamill.org>",
- "Dirk Van Haerenborgh <vhdirk@gmail.com>"]
+version = "0.0.5"
+authors = ["Dirk Van Haerenborgh <vhdirk@gmail.com>"]
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<P: AsRef<path::Path>, 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<P: AsRef<path::Path>>(&self, path: &P) -> Result<Option<Directory>> {
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<Option<Messages>>
{
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<u32>
{
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<Option<Threads>>
{
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<u32>
{
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()
+ }
+ }
+}