aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/directory.rs9
-rw-r--r--src/query.rs24
2 files changed, 28 insertions, 5 deletions
diff --git a/src/directory.rs b/src/directory.rs
index eaf706e..3d9de6e 100644
--- a/src/directory.rs
+++ b/src/directory.rs
@@ -1,4 +1,5 @@
use std::{
+ ops,
marker,
};
@@ -20,3 +21,11 @@ impl<'d> NewFromPtr<*mut ffi::notmuch_directory_t> for Directory<'d> {
Directory(ptr, marker::PhantomData)
}
}
+
+impl<'d> ops::Drop for Directory<'d> {
+ fn drop(&mut self) {
+ unsafe {
+ ffi::notmuch_directory_destroy(self.0)
+ };
+ }
+}
diff --git a/src/query.rs b/src/query.rs
index 24a2a1b..18d44d7 100644
--- a/src/query.rs
+++ b/src/query.rs
@@ -1,24 +1,38 @@
use std::{
ops,
+ marker
};
use error::Result;
use ffi;
+use utils::{
+ NewFromPtr,
+};
+use Database;
-use database::Database;
#[derive(Debug)]
-pub struct Query(pub(crate) *mut ffi::notmuch_query_t);
+pub struct Query<'d>(
+ pub(crate) *mut ffi::notmuch_query_t,
+ marker::PhantomData<&'d mut Database>,
+);
+
-impl Query {
- pub fn create(db: &Database, query_string: &String) -> Result<Self> {
+impl<'d> Query<'d> {
+ pub fn create(db: &'d Database, query_string: &String) -> Result<Self> {
db.create_query(query_string)
}
}
+impl<'d> NewFromPtr<*mut ffi::notmuch_query_t> for Query<'d> {
+ fn new(ptr: *mut ffi::notmuch_query_t) -> Query<'d> {
+ Query(ptr, marker::PhantomData)
+ }
+}
+
-impl ops::Drop for Query {
+impl<'d> ops::Drop for Query<'d> {
fn drop(&mut self) {
unsafe {
ffi::notmuch_query_destroy(self.0)