diff options
Diffstat (limited to 'src/filenames.rs')
| -rw-r--r-- | src/filenames.rs | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/filenames.rs b/src/filenames.rs index ad4c3e9..a4440d3 100644 --- a/src/filenames.rs +++ b/src/filenames.rs @@ -3,34 +3,27 @@ use std::iter::Iterator; use std::ops::Drop; use std::path::PathBuf; -use supercow::Phantomcow; - -use crate::ffi; +use ffi; +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) }; - } - } +pub struct Filenames<'o, O> +where + O: FilenamesOwner + 'o, +{ + pub(crate) ptr: *mut ffi::notmuch_filenames_t, + pub(crate) marker: ScopedPhantomcow<'o, O>, } -#[derive(Debug)] -pub struct Filenames<'o, O> +impl<'o, O> Drop for Filenames<'o, O> where - O: FilenamesOwner, + O: FilenamesOwner + 'o, { - pub(crate) handle: FilenamesPtr, - pub(crate) marker: Phantomcow<'o, O>, + fn drop(self: &mut Self) { + unsafe { ffi::notmuch_filenames_destroy(self.ptr) }; + } } impl<'o, O> Filenames<'o, O> @@ -39,10 +32,10 @@ where { pub fn from_ptr<P>(ptr: *mut ffi::notmuch_filenames_t, owner: P) -> Filenames<'o, O> where - P: Into<Phantomcow<'o, O>>, + P: Into<ScopedPhantomcow<'o, O>>, { Filenames { - handle: FilenamesPtr { ptr }, + ptr, marker: owner.into(), } } @@ -55,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) }; |
