1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
use std::ops::Drop;
use supercow::Supercow;
use ffi;
use Database;
use Filenames;
use FilenamesOwner;
use utils::{ScopedSupercow, ScopedPhantomcow};
#[derive(Debug)]
pub struct Directory<'d> {
ptr: *mut ffi::notmuch_directory_t,
marker: ScopedPhantomcow<'d, Database>,
}
impl<'d> Drop for Directory<'d> {
fn drop(&mut self) {
unsafe { ffi::notmuch_directory_destroy(self.ptr) };
}
}
impl<'d> FilenamesOwner for Directory<'d> {}
impl<'d> Directory<'d> {
pub(crate) fn from_ptr<O>(ptr: *mut ffi::notmuch_directory_t, owner: O) -> Directory<'d>
where
O: Into<ScopedPhantomcow<'d, Database>>,
{
Directory {
ptr,
marker: owner.into(),
}
}
pub fn child_directories(&self) -> Filenames<Self> {
<Self as DirectoryExt>::child_directories(self)
}
}
pub trait DirectoryExt<'d> {
fn child_directories<'s, S>(directory: S) -> Filenames<'s, Directory<'d>>
where
S: Into<ScopedSupercow<'s, Directory<'d>>>,
{
let dir = directory.into();
Filenames::from_ptr(
unsafe { ffi::notmuch_directory_get_child_directories(dir.ptr) },
Supercow::phantom(dir),
)
}
}
impl<'d> DirectoryExt<'d> for Directory<'d> {}
unsafe impl<'d> Send for Directory<'d> {}
unsafe impl<'d> Sync for Directory<'d> {}
|