aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-10-29 21:54:48 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-10-29 21:54:48 +0100
commit304786cbfd8d2d425eb7119b974ca9cb416a6ee0 (patch)
tree923ce4ab4e68f8531bc194a6808f78bb62cebf1e
parentbd1a184600a0d42c36d7d2fc5f010692d0ab46aa (diff)
downloadmail-304786cbfd8d2d425eb7119b974ca9cb416a6ee0.tar.gz
fix lifetimes of tags
-rw-r--r--Cargo.toml3
-rw-r--r--src/database.rs4
-rw-r--r--src/message.rs4
-rw-r--r--src/messages.rs4
-rw-r--r--src/tags.rs16
-rw-r--r--src/thread.rs2
-rw-r--r--tests/main.rs3
7 files changed, 22 insertions, 14 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 7711237..cc152bf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,9 @@ travis-ci = { repository = "vhdirk/notmuch-rs" }
libc = "0.2"
clippy = { version = "0.0.193", optional = true }
+[dev-dependencies]
+dirs = "1.0"
+
[features]
v0_21 = []
v0_26 = ["v0_21"]
diff --git a/src/database.rs b/src/database.rs
index 7a1bb63..467c3ba 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -77,7 +77,7 @@ impl Database {
Ok(Database{handle:DatabasePtr{ptr:db}})
}
- pub fn close(self) -> Result<()> {
+ pub fn close(&mut self) -> Result<()> {
try!(unsafe {
ffi::notmuch_database_close(self.handle.ptr)
}.as_result());
@@ -217,7 +217,7 @@ impl Database {
Ok(Query::from_ptr(query))
}
- pub fn all_tags<'d>(&self) -> Result<Tags> {
+ pub fn all_tags<'d>(&self) -> Result<Tags<'d, Self>> {
let tags = unsafe {
ffi::notmuch_database_get_all_tags(self.handle.ptr)
diff --git a/src/message.rs b/src/message.rs
index c5a6404..2825c1a 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -16,6 +16,7 @@ use Filenames;
use Tags;
use messages::MessagesOwner;
use filenames::FilenamesOwner;
+use tags::TagsOwner;
pub trait MessageOwner{}
@@ -40,6 +41,7 @@ pub struct Message<'o, Owner: MessageOwner>{
impl<'o, Owner: MessageOwner> MessagesOwner for Message<'o, Owner>{}
impl<'o, Owner: MessageOwner> FilenamesOwner for Message<'o, Owner>{}
+impl<'o, Owner: MessageOwner> TagsOwner for Message<'o, Owner>{}
impl<'o, Owner: MessageOwner> FromPtr<*mut ffi::notmuch_message_t> for Message<'o, Owner> {
@@ -104,7 +106,7 @@ impl<'o, Owner: MessageOwner> Message<'o, Owner>{
}
}
- pub fn tags(self: &Self) -> Tags{
+ pub fn tags<'m>(self: &Self) -> Tags<'m, Self>{
Tags::from_ptr(unsafe {
ffi::notmuch_message_get_tags(self.handle.ptr)
})
diff --git a/src/messages.rs b/src/messages.rs
index 40929eb..ef196e5 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -10,6 +10,7 @@ use Query;
use Message;
use Tags;
use message::MessageOwner;
+use tags::TagsOwner;
pub trait MessagesOwner{
}
@@ -52,6 +53,7 @@ impl<'o, Owner: MessagesOwner> FromPtr<*mut ffi::notmuch_messages_t> for Message
}
impl<'o, Owner: MessagesOwner> MessageOwner for Messages<'o, Owner>{}
+impl<'o, Owner: MessagesOwner> TagsOwner for Messages<'o, Owner>{}
impl<'o, Owner: MessagesOwner> Messages<'o, Owner>{
@@ -69,7 +71,7 @@ impl<'o, Owner: MessagesOwner> Messages<'o, Owner>{
*
* The function returns NULL on error.
*/
- pub fn collect_tags(self: &'o Self) -> Tags{
+ pub fn collect_tags<'m>(self: &'o Self) -> Tags<'m, Self>{
Tags::from_ptr(unsafe {
ffi::notmuch_messages_collect_tags(self.handle.ptr)
})
diff --git a/src/tags.rs b/src/tags.rs
index 5cac5ba..7df5e5d 100644
--- a/src/tags.rs
+++ b/src/tags.rs
@@ -14,18 +14,18 @@ pub trait TagsOwner{}
#[derive(Debug)]
-pub struct Tags<'d>(
+pub struct Tags<'o, Owner: TagsOwner>(
*mut ffi::notmuch_tags_t,
- PhantomData<&'d Database>,
+ PhantomData<&'o Owner>,
);
-impl<'d> FromPtr<*mut ffi::notmuch_tags_t> for Tags<'d> {
- fn from_ptr(ptr: *mut ffi::notmuch_tags_t) -> Tags<'d> {
+impl<'o, Owner: TagsOwner> FromPtr<*mut ffi::notmuch_tags_t> for Tags<'o, Owner> {
+ fn from_ptr(ptr: *mut ffi::notmuch_tags_t) -> Tags<'o, Owner> {
Tags(ptr, PhantomData)
}
}
-impl<'d> Drop for Tags<'d> {
+impl<'o, Owner: TagsOwner> Drop for Tags<'o, Owner> {
fn drop(&mut self) {
unsafe {
ffi::notmuch_tags_destroy(self.0)
@@ -33,7 +33,7 @@ impl<'d> Drop for Tags<'d> {
}
}
-impl<'d> Iterator for Tags<'d> {
+impl<'o, Owner: TagsOwner> Iterator for Tags<'o, Owner> {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
@@ -57,5 +57,5 @@ impl<'d> Iterator for Tags<'d> {
}
}
-unsafe impl<'d> Send for Tags<'d>{}
-unsafe impl<'d> Sync for Tags<'d>{}
+unsafe impl<'o, Owner: TagsOwner> Send for Tags<'o, Owner>{}
+unsafe impl<'o, Owner: TagsOwner> Sync for Tags<'o, Owner>{}
diff --git a/src/thread.rs b/src/thread.rs
index 1cf163e..1ba865e 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -86,7 +86,7 @@ impl<'o, Owner: ThreadOwner> Thread<'o, Owner>{
}
- pub fn tags<'t>(self: &Self) -> Tags{
+ pub fn tags<'t>(self: &Self) -> Tags<'t, Self>{
Tags::from_ptr(unsafe {
ffi::notmuch_thread_get_tags(self.handle.ptr)
})
diff --git a/tests/main.rs b/tests/main.rs
index 8c68ca3..6840dc0 100644
--- a/tests/main.rs
+++ b/tests/main.rs
@@ -1,8 +1,9 @@
extern crate notmuch;
+extern crate dirs;
fn main() {
- let mut mail_path = std::env::home_dir().unwrap();
+ let mut mail_path = dirs::home_dir().unwrap();
mail_path.push(".mail");
match notmuch::Database::open(&mail_path.to_str().unwrap().to_string(), notmuch::DatabaseMode::ReadOnly){