diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-05 08:15:27 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-05 08:15:27 +0100 |
| commit | 942740b143c8f07f402da8e20338c8f769fe5447 (patch) | |
| tree | 738254b10ded304175c8e5b94f25c28caca303aa /src/directory.rs | |
| parent | 228e7665bc4dc20929ea2a8cb52600da3d4dd839 (diff) | |
| download | mail-942740b143c8f07f402da8e20338c8f769fe5447.tar.gz | |
implement 'Ext' traits for all types exept iterators
Diffstat (limited to 'src/directory.rs')
| -rw-r--r-- | src/directory.rs | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/src/directory.rs b/src/directory.rs index 8ddc044..0aa5b80 100644 --- a/src/directory.rs +++ b/src/directory.rs @@ -40,41 +40,25 @@ 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> { + <Self as DirectoryExt>::child_directories(self) } +} - - pub fn child_directories(&self) -> Filenames<Self> { +pub trait DirectoryExt<'d>{ + fn child_directories<'s, S: Into<Supercow<'s, Directory<'d>>>>(directory: S) -> Filenames<'s, Directory<'d>> { + let dir = directory.into(); Filenames::from_ptr( - unsafe { ffi::notmuch_directory_get_child_directories(self.handle.ptr) }, - self, + unsafe { ffi::notmuch_directory_get_child_directories(dir.handle.ptr) }, + Supercow::phantom(dir), ) } } -pub trait DirectoryExt<'d>{ +impl<'d> DirectoryExt<'d> for Directory<'d>{ } + unsafe impl<'d> Send for Directory<'d> {} unsafe impl<'d> Sync for Directory<'d> {} |
