aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-20 08:21:03 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2018-12-20 08:21:03 +0100
commitbb8a60ddc9fdecc6c1004639514b538578e37532 (patch)
tree634968cabab56edec2f8a750903c155800a0f031
parent2baa9d13ad4c5c2c6e55b6ca49c92a4d2434fba7 (diff)
downloadmail-bb8a60ddc9fdecc6c1004639514b538578e37532.tar.gz
remove ptr indirection
-rw-r--r--src/database.rs47
-rw-r--r--src/directory.rs18
-rw-r--r--src/filenames.rs34
-rw-r--r--src/message.rs35
-rw-r--r--src/messages.rs32
-rw-r--r--src/query.rs44
-rw-r--r--src/tags.rs26
-rw-r--r--src/thread.rs44
-rw-r--r--src/threads.rs30
9 files changed, 128 insertions, 182 deletions
diff --git a/src/database.rs b/src/database.rs
index f4ef444..027a43f 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -10,7 +10,6 @@ use libc;
use error::{Error, Result};
use ffi;
use ffi::Status;
-use query::QueryPtr;
use utils::ToStr;
use Directory;
use Query;
@@ -31,32 +30,18 @@ pub struct Revision {
pub uuid: String,
}
+
#[derive(Debug)]
-pub(crate) struct DatabasePtr {
- pub ptr: *mut ffi::notmuch_database_t,
+pub struct Database {
+ pub(crate) ptr: *mut ffi::notmuch_database_t,
}
-impl Drop for DatabasePtr {
+impl Drop for Database {
fn drop(&mut self) {
unsafe { ffi::notmuch_database_destroy(self.ptr) };
}
}
-impl DatabasePtr {
- pub(crate) fn create_query(&self, query_string: &str) -> Result<QueryPtr> {
- let query_str = CString::new(query_string).unwrap();
-
- let query = unsafe { ffi::notmuch_query_create(self.ptr, query_str.as_ptr()) };
-
- Ok(QueryPtr { ptr: query })
- }
-}
-
-#[derive(Debug)]
-pub struct Database {
- pub(crate) handle: DatabasePtr,
-}
-
impl TagsOwner for Database {}
impl Database {
@@ -70,7 +55,7 @@ impl Database {
unsafe { ffi::notmuch_database_create(path_str.as_ptr(), &mut db) }.as_result()?;
Ok(Database {
- handle: DatabasePtr { ptr: db },
+ ptr: db,
})
}
@@ -85,12 +70,12 @@ impl Database {
.as_result()?;
Ok(Database {
- handle: DatabasePtr { ptr: db },
+ ptr: db,
})
}
pub fn close(&mut self) -> Result<()> {
- unsafe { ffi::notmuch_database_close(self.handle.ptr) }.as_result()?;
+ unsafe { ffi::notmuch_database_close(self.ptr) }.as_result()?;
Ok(())
}
@@ -147,14 +132,14 @@ impl Database {
pub fn path(&self) -> &Path {
Path::new(
- unsafe { ffi::notmuch_database_get_path(self.handle.ptr) }
+ unsafe { ffi::notmuch_database_get_path(self.ptr) }
.to_str()
.unwrap(),
)
}
pub fn version(&self) -> Version {
- Version(unsafe { ffi::notmuch_database_get_version(self.handle.ptr) })
+ Version(unsafe { ffi::notmuch_database_get_version(self.ptr) })
}
#[cfg(feature = "v0_21")]
@@ -162,7 +147,7 @@ impl Database {
let uuid_p: *const libc::c_char = ptr::null();
let revision = unsafe {
ffi::notmuch_database_get_revision(
- self.handle.ptr,
+ self.ptr,
(&uuid_p) as *const _ as *mut *const libc::c_char,
)
};
@@ -176,7 +161,7 @@ impl Database {
}
pub fn needs_upgrade(&self) -> bool {
- unsafe { ffi::notmuch_database_needs_upgrade(self.handle.ptr) == 1 }
+ unsafe { ffi::notmuch_database_needs_upgrade(self.ptr) == 1 }
}
pub fn upgrade<F>(&mut self) -> Result<()>
@@ -209,7 +194,7 @@ impl Database {
unsafe {
ffi::notmuch_database_upgrade(
- self.handle.ptr,
+ self.ptr,
if status.is_some() {
Some(wrapper::<F>)
} else {
@@ -253,7 +238,7 @@ pub trait DatabaseExt {
let dbref = database.into();
let query_str = CString::new(query_string).unwrap();
- let query = unsafe { ffi::notmuch_query_create(dbref.handle.ptr, query_str.as_ptr()) };
+ let query = unsafe { ffi::notmuch_query_create(dbref.ptr, query_str.as_ptr()) };
Ok(Query::from_ptr(query, Supercow::phantom(dbref)))
}
@@ -264,7 +249,7 @@ pub trait DatabaseExt {
{
let dbref = database.into();
- let tags = unsafe { ffi::notmuch_database_get_all_tags(dbref.handle.ptr) };
+ let tags = unsafe { ffi::notmuch_database_get_all_tags(dbref.ptr) };
Ok(Tags::from_ptr(tags, ScopedSupercow::phantom(dbref)))
}
@@ -280,7 +265,7 @@ pub trait DatabaseExt {
let mut dir = ptr::null_mut();
unsafe {
- ffi::notmuch_database_get_directory(dbref.handle.ptr, path_str.as_ptr(), &mut dir)
+ ffi::notmuch_database_get_directory(dbref.ptr, path_str.as_ptr(), &mut dir)
}.as_result()?;
if dir.is_null() {
@@ -300,7 +285,7 @@ pub trait DatabaseExt {
Some(path_str) => {
let msg_path = CString::new(path_str).unwrap();
- unsafe { ffi::notmuch_database_remove_message(dbref.handle.ptr, msg_path.as_ptr()) }
+ unsafe { ffi::notmuch_database_remove_message(dbref.ptr, msg_path.as_ptr()) }
.as_result()
}
None => Err(Error::NotmuchError(Status::FileError)),
diff --git a/src/directory.rs b/src/directory.rs
index 1aff32b..8f09ed7 100644
--- a/src/directory.rs
+++ b/src/directory.rs
@@ -7,23 +7,19 @@ use Filenames;
use FilenamesOwner;
use utils::{ScopedSupercow, ScopedPhantomcow};
+
#[derive(Debug)]
-pub(crate) struct DirectoryPtr {
- pub ptr: *mut ffi::notmuch_directory_t,
+pub struct Directory<'d> {
+ ptr: *mut ffi::notmuch_directory_t,
+ marker: ScopedPhantomcow<'d, Database>,
}
-impl Drop for DirectoryPtr {
+impl<'d> Drop for Directory<'d> {
fn drop(&mut self) {
unsafe { ffi::notmuch_directory_destroy(self.ptr) };
}
}
-#[derive(Debug)]
-pub struct Directory<'d> {
- handle: DirectoryPtr,
- marker: ScopedPhantomcow<'d, Database>,
-}
-
impl<'d> FilenamesOwner for Directory<'d> {}
impl<'d> Directory<'d> {
@@ -32,7 +28,7 @@ impl<'d> Directory<'d> {
O: Into<ScopedPhantomcow<'d, Database>>,
{
Directory {
- handle: DirectoryPtr { ptr },
+ ptr,
marker: owner.into(),
}
}
@@ -49,7 +45,7 @@ pub trait DirectoryExt<'d> {
{
let dir = directory.into();
Filenames::from_ptr(
- unsafe { ffi::notmuch_directory_get_child_directories(dir.handle.ptr) },
+ unsafe { ffi::notmuch_directory_get_child_directories(dir.ptr) },
Supercow::phantom(dir),
)
}
diff --git a/src/filenames.rs b/src/filenames.rs
index 94eb5b7..a4440d3 100644
--- a/src/filenames.rs
+++ b/src/filenames.rs
@@ -9,29 +9,23 @@ use utils::ScopedPhantomcow;
pub trait FilenamesOwner {}
#[derive(Debug)]
-pub(crate) struct FilenamesPtr {
- pub ptr: *mut ffi::notmuch_filenames_t,
-}
-
-impl Drop for FilenamesPtr {
- fn drop(self: &mut Self) {
- let valid = unsafe { ffi::notmuch_filenames_valid(self.ptr) };
-
- if valid != 0 {
- unsafe { ffi::notmuch_filenames_destroy(self.ptr) };
- }
- }
-}
-
-#[derive(Debug)]
pub struct Filenames<'o, O>
where
O: FilenamesOwner + 'o,
{
- pub(crate) handle: FilenamesPtr,
+ pub(crate) ptr: *mut ffi::notmuch_filenames_t,
pub(crate) marker: ScopedPhantomcow<'o, O>,
}
+impl<'o, O> Drop for Filenames<'o, O>
+where
+ O: FilenamesOwner + 'o,
+{
+ fn drop(self: &mut Self) {
+ unsafe { ffi::notmuch_filenames_destroy(self.ptr) };
+ }
+}
+
impl<'o, O> Filenames<'o, O>
where
O: FilenamesOwner + 'o,
@@ -41,7 +35,7 @@ where
P: Into<ScopedPhantomcow<'o, O>>,
{
Filenames {
- handle: FilenamesPtr { ptr },
+ ptr,
marker: owner.into(),
}
}
@@ -54,15 +48,15 @@ where
type Item = PathBuf;
fn next(self: &mut Self) -> Option<Self::Item> {
- let valid = unsafe { ffi::notmuch_filenames_valid(self.handle.ptr) };
+ let valid = unsafe { ffi::notmuch_filenames_valid(self.ptr) };
if valid == 0 {
return None;
}
let ctag = unsafe {
- let t = ffi::notmuch_filenames_get(self.handle.ptr);
- ffi::notmuch_filenames_move_to_next(self.handle.ptr);
+ let t = ffi::notmuch_filenames_get(self.ptr);
+ ffi::notmuch_filenames_move_to_next(self.ptr);
CStr::from_ptr(t)
};
diff --git a/src/message.rs b/src/message.rs
index b2b466f..226d3b8 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -15,16 +15,11 @@ use TagsOwner;
pub trait MessageOwner: Send + Sync {}
#[derive(Debug)]
-pub(crate) struct MessagePtr {
- pub ptr: *mut ffi::notmuch_message_t,
-}
-
-#[derive(Debug)]
pub struct Message<'o, O>
where
O: MessageOwner + 'o,
{
- pub(crate) handle: MessagePtr,
+ pub(crate) ptr: *mut ffi::notmuch_message_t,
marker: RefCell<ScopedPhantomcow<'o, O>>,
}
@@ -41,24 +36,24 @@ where
P: Into<ScopedPhantomcow<'o, O>>,
{
Message {
- handle: MessagePtr { ptr },
+ ptr,
marker: RefCell::new(owner.into()),
}
}
pub fn id(self: &Self) -> String {
- let mid = unsafe { ffi::notmuch_message_get_message_id(self.handle.ptr) };
+ let mid = unsafe { ffi::notmuch_message_get_message_id(self.ptr) };
mid.to_str().unwrap().to_string()
}
pub fn thread_id(self: &Self) -> String {
- let tid = unsafe { ffi::notmuch_message_get_thread_id(self.handle.ptr) };
+ let tid = unsafe { ffi::notmuch_message_get_thread_id(self.ptr) };
tid.to_str().unwrap().to_string()
}
pub fn replies(self: &Self) -> Messages<'o, O> {
Messages::<'o, O>::from_ptr(
- unsafe { ffi::notmuch_message_get_replies(self.handle.ptr) },
+ unsafe { ffi::notmuch_message_get_replies(self.ptr) },
// will never panic since the borrow is released immediately
ScopedPhantomcow::<'o, O>::share(&mut *(self.marker.borrow_mut()))
)
@@ -66,7 +61,7 @@ where
#[cfg(feature = "v0_26")]
pub fn count_files(self: &Self) -> i32 {
- unsafe { ffi::notmuch_message_count_files(self.handle.ptr) }
+ unsafe { ffi::notmuch_message_count_files(self.ptr) }
}
pub fn filenames(self: &Self) -> Filenames<Self> {
@@ -75,19 +70,19 @@ where
pub fn filename(self: &Self) -> PathBuf {
PathBuf::from(
- unsafe { ffi::notmuch_message_get_filename(self.handle.ptr) }
+ unsafe { ffi::notmuch_message_get_filename(self.ptr) }
.to_str()
.unwrap(),
)
}
pub fn date(&self) -> i64 {
- unsafe { ffi::notmuch_message_get_date(self.handle.ptr) as i64 }
+ unsafe { ffi::notmuch_message_get_date(self.ptr) as i64 }
}
pub fn header(&self, name: &str) -> Result<Option<&str>> {
let name = CString::new(name).unwrap();
- let ret = unsafe { ffi::notmuch_message_get_header(self.handle.ptr, name.as_ptr()) };
+ let ret = unsafe { ffi::notmuch_message_get_header(self.ptr, name.as_ptr()) };
if ret.is_null() {
Err(Error::UnspecifiedError)
} else {
@@ -104,16 +99,16 @@ where
pub fn add_tag(self: &Self, tag: &str) -> Result<()> {
let tag = CString::new(tag).unwrap();
- unsafe { ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) }.as_result()
+ unsafe { ffi::notmuch_message_add_tag(self.ptr, tag.as_ptr()) }.as_result()
}
pub fn remove_tag(self: &Self, tag: &str) -> Result<()> {
let tag = CString::new(tag).unwrap();
- unsafe { ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) }.as_result()
+ unsafe { ffi::notmuch_message_remove_tag(self.ptr, tag.as_ptr()) }.as_result()
}
pub fn remove_all_tags(self: &Self) -> Result<()> {
- unsafe { ffi::notmuch_message_remove_all_tags(self.handle.ptr) }.as_result()
+ unsafe { ffi::notmuch_message_remove_all_tags(self.ptr) }.as_result()
}
}
@@ -127,7 +122,7 @@ where
{
let messageref = message.into();
Tags::from_ptr(
- unsafe { ffi::notmuch_message_get_tags(messageref.handle.ptr) },
+ unsafe { ffi::notmuch_message_get_tags(messageref.ptr) },
Supercow::phantom(messageref),
)
}
@@ -138,7 +133,7 @@ where
// {
// let messageref = message.into();
// Messages::from_ptr(
- // unsafe { ffi::notmuch_message_get_replies(messageref.handle.ptr) },
+ // unsafe { ffi::notmuch_message_get_replies(messageref.ptr) },
// Supercow::phantom(messageref),
// )
// }
@@ -149,7 +144,7 @@ where
{
let messageref = message.into();
Filenames::from_ptr(
- unsafe { ffi::notmuch_message_get_filenames(messageref.handle.ptr) },
+ unsafe { ffi::notmuch_message_get_filenames(messageref.ptr) },
Supercow::phantom(messageref),
)
}
diff --git a/src/messages.rs b/src/messages.rs
index db92f73..01e0ea4 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -8,25 +8,23 @@ use Tags;
use TagsOwner;
#[derive(Debug)]
-pub struct MessagesPtr {
- pub ptr: *mut ffi::notmuch_messages_t,
-}
-
-impl Drop for MessagesPtr {
- fn drop(self: &mut Self) {
- unsafe { ffi::notmuch_messages_destroy(self.ptr) };
- }
-}
-
-#[derive(Debug)]
pub struct Messages<'o, O>
where
O: MessageOwner + 'o,
{
- pub(crate) handle: MessagesPtr,
+ pub(crate) ptr: *mut ffi::notmuch_messages_t,
marker: ScopedPhantomcow<'o, O>,
}
+impl<'o, O> Drop for Messages<'o, O>
+where
+ O: MessageOwner + 'o,
+{
+ fn drop(self: &mut Self) {
+ unsafe { ffi::notmuch_messages_destroy(self.ptr) };
+ }
+}
+
impl<'o, O> Messages<'o, O>
where
O: MessageOwner + 'o,
@@ -36,7 +34,7 @@ where
P: Into<ScopedPhantomcow<'o, O>>,
{
Messages {
- handle: MessagesPtr { ptr },
+ ptr,
marker: owner.into(),
}
}
@@ -64,7 +62,7 @@ where
*/
pub fn collect_tags<'m>(self: &'o Self) -> Tags<'m, Self> {
Tags::from_ptr(
- unsafe { ffi::notmuch_messages_collect_tags(self.handle.ptr) },
+ unsafe { ffi::notmuch_messages_collect_tags(self.ptr) },
self,
)
}
@@ -77,15 +75,15 @@ where
type Item = Message<'o, O>;
fn next(&mut self) -> Option<Self::Item> {
- let valid = unsafe { ffi::notmuch_messages_valid(self.handle.ptr) };
+ let valid = unsafe { ffi::notmuch_messages_valid(self.ptr) };
if valid == 0 {
return None;
}
let cthrd = unsafe {
- let thrd = ffi::notmuch_messages_get(self.handle.ptr);
- ffi::notmuch_messages_move_to_next(self.handle.ptr);
+ let thrd = ffi::notmuch_messages_get(self.ptr);
+ ffi::notmuch_messages_move_to_next(self.ptr);
thrd
};
diff --git a/src/query.rs b/src/query.rs
index adbed58..127a9ab 100644
--- a/src/query.rs
+++ b/src/query.rs
@@ -10,25 +10,21 @@ use Database;
use Messages;
use MessageOwner;
use Threads;
+use DatabaseExt;
use utils::ScopedSupercow;
#[derive(Debug)]
-pub(crate) struct QueryPtr {
- pub ptr: *mut ffi::notmuch_query_t,
+pub struct Query<'d> {
+ pub(crate) ptr: *mut ffi::notmuch_query_t,
+ marker: Phantomcow<'d, Database>,
}
-impl Drop for QueryPtr {
+impl<'d> Drop for Query<'d> {
fn drop(&mut self) {
unsafe { ffi::notmuch_query_destroy(self.ptr) };
}
}
-#[derive(Debug)]
-pub struct Query<'d> {
- pub(crate) handle: QueryPtr,
- marker: Phantomcow<'d, Database>,
-}
-
impl<'d> MessageOwner for Query<'d> {}
impl<'d> Query<'d> {
@@ -37,17 +33,7 @@ impl<'d> Query<'d> {
O: Into<Phantomcow<'d, Database>>,
{
Query {
- handle: QueryPtr { ptr },
- marker: owner.into(),
- }
- }
-
- pub(crate) fn from_handle<O>(handle: QueryPtr, owner: O) -> Query<'d>
- where
- O: Into<Phantomcow<'d, Database>>,
- {
- Query {
- handle,
+ ptr,
marker: owner.into(),
}
}
@@ -56,22 +42,18 @@ impl<'d> Query<'d> {
where
D: Into<Supercow<'d, Database>>,
{
- let dbref = db.into();
- dbref
- .handle
- .create_query(query_string)
- .map(move |handle| Query::from_handle(handle, Supercow::phantom(dbref)))
+ <Database as DatabaseExt>::create_query(db, query_string)
}
/// Specify the sorting desired for this query.
pub fn set_sort(self: &Self, sort: Sort) {
- unsafe { ffi::notmuch_query_set_sort(self.handle.ptr, sort.into()) }
+ unsafe { ffi::notmuch_query_set_sort(self.ptr, sort.into()) }
}
/// Return the sort specified for this query. See
/// `set_sort`.
pub fn sort(self: &Self) -> Sort {
- unsafe { ffi::notmuch_query_get_sort(self.handle.ptr) }.into()
+ unsafe { ffi::notmuch_query_get_sort(self.ptr) }.into()
}
/// Filter messages according to the query and return
@@ -81,7 +63,7 @@ impl<'d> Query<'d> {
pub fn count_messages(self: &Self) -> Result<u32> {
let mut cnt = 0;
- unsafe { ffi::notmuch_query_count_messages(self.handle.ptr, &mut cnt) }.as_result()?;
+ unsafe { ffi::notmuch_query_count_messages(self.ptr, &mut cnt) }.as_result()?;
Ok(cnt)
}
@@ -92,7 +74,7 @@ impl<'d> Query<'d> {
pub fn count_threads(self: &Self) -> Result<u32> {
let mut cnt = 0;
- unsafe { ffi::notmuch_query_count_threads(self.handle.ptr, &mut cnt) }.as_result()?;
+ unsafe { ffi::notmuch_query_count_threads(self.ptr, &mut cnt) }.as_result()?;
Ok(cnt)
}
@@ -106,7 +88,7 @@ pub trait QueryExt<'d> {
let queryref = query.into();
let mut thrds = ptr::null_mut();
- unsafe { ffi::notmuch_query_search_threads(queryref.handle.ptr, &mut thrds) }
+ unsafe { ffi::notmuch_query_search_threads(queryref.ptr, &mut thrds) }
.as_result()?;
Ok(Threads::from_ptr(thrds, ScopedSupercow::phantom(queryref)))
@@ -119,7 +101,7 @@ pub trait QueryExt<'d> {
let queryref = query.into();
let mut msgs = ptr::null_mut();
- unsafe { ffi::notmuch_query_search_messages(queryref.handle.ptr, &mut msgs) }
+ unsafe { ffi::notmuch_query_search_messages(queryref.ptr, &mut msgs) }
.as_result()?;
Ok(Messages::from_ptr(msgs, ScopedSupercow::phantom(queryref)))
diff --git a/src/tags.rs b/src/tags.rs
index df9e854..ad8e421 100644
--- a/src/tags.rs
+++ b/src/tags.rs
@@ -8,22 +8,22 @@ use utils::ScopedPhantomcow;
pub trait TagsOwner {}
#[derive(Debug)]
-pub(crate) struct TagsPtr {
- pub ptr: *mut ffi::notmuch_tags_t,
+pub struct Tags<'o, O> where
+ O: TagsOwner + 'o,
+{
+ ptr: *mut ffi::notmuch_tags_t,
+ marker: ScopedPhantomcow<'o, O>,
}
-impl Drop for TagsPtr {
+impl<'o, O> Drop for Tags<'o, O>
+where
+ O: TagsOwner + 'o,
+{
fn drop(&mut self) {
unsafe { ffi::notmuch_tags_destroy(self.ptr) };
}
}
-#[derive(Debug)]
-pub struct Tags<'o, Owner: TagsOwner + 'o> {
- handle: TagsPtr,
- marker: ScopedPhantomcow<'o, Owner>,
-}
-
impl<'o, O> Tags<'o, O>
where
O: TagsOwner + 'o,
@@ -33,7 +33,7 @@ where
P: Into<ScopedPhantomcow<'o, O>>,
{
Tags {
- handle: TagsPtr { ptr },
+ ptr,
marker: owner.into(),
}
}
@@ -46,15 +46,15 @@ where
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
- let valid = unsafe { ffi::notmuch_tags_valid(self.handle.ptr) };
+ let valid = unsafe { ffi::notmuch_tags_valid(self.ptr) };
if valid == 0 {
return None;
}
let ctag = unsafe {
- let t = ffi::notmuch_tags_get(self.handle.ptr);
- ffi::notmuch_tags_move_to_next(self.handle.ptr);
+ let t = ffi::notmuch_tags_get(self.ptr);
+ ffi::notmuch_tags_move_to_next(self.ptr);
CStr::from_ptr(t)
};
diff --git a/src/thread.rs b/src/thread.rs
index 137c936..9634a57 100644
--- a/src/thread.rs
+++ b/src/thread.rs
@@ -9,25 +9,23 @@ use TagsOwner;
use Query;
#[derive(Debug)]
-pub(crate) struct ThreadPtr {
- pub ptr: *mut ffi::notmuch_thread_t,
-}
-
-impl Drop for ThreadPtr {
- fn drop(&mut self) {
- unsafe { ffi::notmuch_thread_destroy(self.ptr) };
- }
-}
-
-#[derive(Debug)]
pub struct Thread<'d, 'q>
where
'd: 'q
{
- pub(crate) handle: ThreadPtr,
+ pub(crate) ptr: *mut ffi::notmuch_thread_t,
pub(crate) marker: ScopedPhantomcow<'q, Query<'d>>,
}
+impl<'d, 'q> Drop for Thread<'d, 'q>
+where
+ 'd: 'q
+{
+ fn drop(&mut self) {
+ unsafe { ffi::notmuch_thread_destroy(self.ptr) };
+ }
+}
+
impl<'d, 'q> MessageOwner for Thread<'d, 'q> where 'd: 'q {}
impl<'d, 'q> TagsOwner for Thread<'d, 'q> where 'd: 'q {}
@@ -40,23 +38,23 @@ where
P: Into<ScopedPhantomcow<'q, Query<'d>>>,
{
Thread {
- handle: ThreadPtr { ptr },
+ ptr,
marker: owner.into(),
}
}
pub fn id(self: &Self) -> String {
- let tid = unsafe { ffi::notmuch_thread_get_thread_id(self.handle.ptr) };
+ let tid = unsafe { ffi::notmuch_thread_get_thread_id(self.ptr) };
tid.to_str().unwrap().to_string()
}
pub fn total_messages(self: &Self) -> i32 {
- unsafe { ffi::notmuch_thread_get_total_messages(self.handle.ptr) }
+ unsafe { ffi::notmuch_thread_get_total_messages(self.ptr) }
}
#[cfg(feature = "0.26")]
pub fn total_files(self: &Self) -> i32 {
- unsafe { ffi::notmuch_thread_get_total_files(self.handle.ptr) }
+ unsafe { ffi::notmuch_thread_get_total_files(self.ptr) }
}
pub fn toplevel_messages(self: &Self) -> Messages<'_, Self> {
@@ -74,13 +72,13 @@ where
}
pub fn subject(self: &Self) -> String {
- let sub = unsafe { ffi::notmuch_thread_get_subject(self.handle.ptr) };
+ let sub = unsafe { ffi::notmuch_thread_get_subject(self.ptr) };
sub.to_str().unwrap().to_string()
}
pub fn authors(self: &Self) -> Vec<String> {
- let athrs = unsafe { ffi::notmuch_thread_get_authors(self.handle.ptr) };
+ let athrs = unsafe { ffi::notmuch_thread_get_authors(self.ptr) };
athrs
.to_str()
@@ -92,12 +90,12 @@ where
/// Get the date of the oldest message in 'thread' as a time_t value.
pub fn oldest_date(self: &Self) -> i64 {
- unsafe { ffi::notmuch_thread_get_oldest_date(self.handle.ptr) as i64 }
+ unsafe { ffi::notmuch_thread_get_oldest_date(self.ptr) as i64 }
}
/// Get the date of the newest message in 'thread' as a time_t value.
pub fn newest_date(self: &Self) -> i64 {
- unsafe { ffi::notmuch_thread_get_newest_date(self.handle.ptr) as i64 }
+ unsafe { ffi::notmuch_thread_get_newest_date(self.ptr) as i64 }
}
}
@@ -111,7 +109,7 @@ where
{
let threadref = thread.into();
Tags::from_ptr(
- unsafe { ffi::notmuch_thread_get_tags(threadref.handle.ptr) },
+ unsafe { ffi::notmuch_thread_get_tags(threadref.ptr) },
ScopedSupercow::phantom(threadref),
)
}
@@ -122,7 +120,7 @@ where
{
let threadref = thread.into();
Messages::from_ptr(
- unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.handle.ptr) },
+ unsafe { ffi::notmuch_thread_get_toplevel_messages(threadref.ptr) },
ScopedSupercow::phantom(threadref),
)
}
@@ -135,7 +133,7 @@ where
{
let threadref = thread.into();
Messages::from_ptr(
- unsafe { ffi::notmuch_thread_get_messages(threadref.handle.ptr) },
+ unsafe { ffi::notmuch_thread_get_messages(threadref.ptr) },
ScopedSupercow::phantom(threadref),
)
}
diff --git a/src/threads.rs b/src/threads.rs
index 6d1e8e4..0359e20 100644
--- a/src/threads.rs
+++ b/src/threads.rs
@@ -7,25 +7,23 @@ use utils::ScopedPhantomcow;
#[derive(Debug)]
-pub(crate) struct ThreadsPtr {
- pub ptr: *mut ffi::notmuch_threads_t,
-}
-
-impl Drop for ThreadsPtr {
- fn drop(&mut self) {
- unsafe { ffi::notmuch_threads_destroy(self.ptr) };
- }
-}
-
-#[derive(Debug)]
pub struct Threads<'d, 'q>
where
'd: 'q
{
- handle: ThreadsPtr,
+ ptr: *mut ffi::notmuch_threads_t,
marker: ScopedPhantomcow<'q, Query<'d>>,
}
+impl<'d, 'q> Drop for Threads<'d, 'q>
+where
+ 'd: 'q,
+{
+ fn drop(&mut self) {
+ unsafe { ffi::notmuch_threads_destroy(self.ptr) };
+ }
+}
+
impl<'d, 'q> Threads<'d, 'q>
where
'd: 'q,
@@ -35,7 +33,7 @@ where
P: Into<ScopedPhantomcow<'q, Query<'d>>>,
{
Threads {
- handle: ThreadsPtr { ptr },
+ ptr,
marker: owner.into(),
}
}
@@ -48,15 +46,15 @@ where
type Item = Thread<'d, 'q>;
fn next(&mut self) -> Option<Self::Item> {
- let valid = unsafe { ffi::notmuch_threads_valid(self.handle.ptr) };
+ let valid = unsafe { ffi::notmuch_threads_valid(self.ptr) };
if valid == 0 {
return None;
}
let cthrd = unsafe {
- let thrd = ffi::notmuch_threads_get(self.handle.ptr);
- ffi::notmuch_threads_move_to_next(self.handle.ptr);
+ let thrd = ffi::notmuch_threads_get(self.ptr);
+ ffi::notmuch_threads_move_to_next(self.ptr);
thrd
};