diff options
Diffstat (limited to 'src/directory.rs')
| -rw-r--r-- | src/directory.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/directory.rs b/src/directory.rs index 9bdae2d..c179eb8 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -1,6 +1,10 @@ +use std::ffi::{CStr, CString}; use std::ops::Drop; -use supercow::Phantomcow; +use std::path::Path; +use std::ptr; +use supercow::{Supercow, Phantomcow}; +use error::Result; use ffi; use Database; use Filenames; @@ -36,6 +40,30 @@ impl<'d> Directory<'d> { } } + pub fn new<O: Into<Supercow<'d, Database>>, + P: AsRef<Path>>(owner: O, path: &P) -> Result<Option<Directory<'d>>> { + let db = owner.into(); + let path_str = CString::new(path.as_ref().to_str().unwrap()).unwrap(); + + let mut dir = ptr::null_mut(); + try!( + unsafe { + ffi::notmuch_database_get_directory(db.handle.ptr, path_str.as_ptr(), &mut dir) + } + .as_result() + ); + + if dir.is_null() { + Ok(None) + } else { + Ok(Some(Directory { + handle: DirectoryPtr { ptr: dir }, + marker: Supercow::phantom(db), + })) + } + } + + pub fn child_directories(&self) -> Filenames<Self> { Filenames::from_ptr( unsafe { ffi::notmuch_directory_get_child_directories(self.handle.ptr) }, |
