diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-03-22 09:56:54 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-03-22 09:56:54 +0100 |
| commit | 64304118fcd8a876815450194a315846b1a95422 (patch) | |
| tree | 3ca94ed00bcdd97c5aa843de3e0b176c200becdd | |
| parent | c1a67ae3ca45cffc1166d2f980a225ff29394bf8 (diff) | |
| download | mail-64304118fcd8a876815450194a315846b1a95422.tar.gz | |
correct lifetime for query
| -rw-r--r-- | src/directory.rs | 9 | ||||
| -rw-r--r-- | src/query.rs | 24 |
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) |
