diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-03-23 07:58:09 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-03-23 07:58:09 +0100 |
| commit | b8eafc5c26f2bab0e2dedad177a8e3b4ecd9e17c (patch) | |
| tree | 47756cd0ed0926e6cbf0e95eceb6aaf62e9f84fa | |
| parent | 6e465aae88a81d849803f964e681974043ca368d (diff) | |
| download | mail-b8eafc5c26f2bab0e2dedad177a8e3b4ecd9e17c.tar.gz | |
filenames iterator
| -rw-r--r-- | src/filenames.rs | 59 | ||||
| -rw-r--r-- | src/lib.rs | 1 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/filenames.rs b/src/filenames.rs new file mode 100644 index 0000000..618d7a8 --- /dev/null +++ b/src/filenames.rs @@ -0,0 +1,59 @@ +use std::{ + ops, + marker, + iter +}; + +use std::ffi::{ + CString, + CStr +}; + +use utils::{ + NewFromPtr, +}; + +use database; +use ffi; + +#[derive(Debug)] +pub struct Filenames<'d>( + *mut ffi::notmuch_filenames_t, + marker::PhantomData<&'d mut database::Database>, +); + +impl<'d> NewFromPtr<*mut ffi::notmuch_filenames_t> for Filenames<'d> { + fn new(ptr: *mut ffi::notmuch_filenames_t) -> Filenames<'d> { + Filenames(ptr, marker::PhantomData) + } +} + +impl<'d> ops::Drop for Filenames<'d> { + fn drop(&mut self) { + unsafe { + ffi::notmuch_filenames_destroy(self.0) + }; + } +} + +impl<'d> iter::Iterator for Filenames<'d> { + type Item = String; + + fn next(&mut self) -> Option<Self::Item> { + + let valid = unsafe { + ffi::notmuch_filenames_valid(self.0) + }; + + if valid == 0{ + return None + } + + let ctag = unsafe { + ffi::notmuch_filenames_move_to_next(self.0); + CStr::from_ptr(ffi::notmuch_filenames_get(self.0)) + }; + + Some(ctag.to_str().unwrap().to_string()) + } +} @@ -23,5 +23,6 @@ pub use message::Message; pub use tags::Tags; pub use threads::Threads; pub use thread::Thread; +pub use filenames::Filenames; pub use ffi::DatabaseMode; |
