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 /src/query.rs | |
| parent | c1a67ae3ca45cffc1166d2f980a225ff29394bf8 (diff) | |
| download | mail-64304118fcd8a876815450194a315846b1a95422.tar.gz | |
correct lifetime for query
Diffstat (limited to 'src/query.rs')
| -rw-r--r-- | src/query.rs | 24 |
1 files changed, 19 insertions, 5 deletions
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) |
